1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5#[serde(tag = "type")]
6pub enum Operation {
7 AddStructField(AddStructFieldOp),
8 UpdateStructField(UpdateStructFieldOp),
9 RemoveStructField(RemoveStructFieldOp),
10 AddStructLiteralField(AddStructLiteralFieldOp),
11 AddEnumVariant(AddEnumVariantOp),
12 UpdateEnumVariant(UpdateEnumVariantOp),
13 RemoveEnumVariant(RemoveEnumVariantOp),
14 AddMatchArm(AddMatchArmOp),
15 UpdateMatchArm(UpdateMatchArmOp),
16 RemoveMatchArm(RemoveMatchArmOp),
17 AddImplMethod(AddImplMethodOp),
18 AddUseStatement(AddUseStatementOp),
19 AddDerive(AddDeriveOp),
20 Transform(TransformOp),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct AddStructFieldOp {
25 pub struct_name: String,
26 pub field_def: String, pub position: InsertPosition,
28 #[serde(default)]
29 pub literal_default: Option<String>, #[serde(default)]
31 pub where_filter: Option<String>, }
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct UpdateStructFieldOp {
36 pub struct_name: String,
37 pub field_def: String, #[serde(default)]
39 pub where_filter: Option<String>, }
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct RemoveStructFieldOp {
44 pub struct_name: String,
45 pub field_name: String, #[serde(default)]
47 pub where_filter: Option<String>, }
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct AddStructLiteralFieldOp {
52 pub struct_name: String,
53 pub field_def: String, pub position: InsertPosition,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct AddEnumVariantOp {
59 pub enum_name: String,
60 pub variant_def: String, pub position: InsertPosition,
62 #[serde(default)]
63 pub where_filter: Option<String>, }
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct UpdateEnumVariantOp {
68 pub enum_name: String,
69 pub variant_def: String, #[serde(default)]
71 pub where_filter: Option<String>, }
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct RemoveEnumVariantOp {
76 pub enum_name: String,
77 pub variant_name: String, #[serde(default)]
79 pub where_filter: Option<String>, }
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct AddMatchArmOp {
84 pub pattern: String, pub body: String, pub function_name: Option<String>, #[serde(default)]
88 pub auto_detect: bool, pub enum_name: Option<String>, }
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct UpdateMatchArmOp {
94 pub pattern: String, pub new_body: String, pub function_name: Option<String>, }
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct RemoveMatchArmOp {
101 pub pattern: String, pub function_name: Option<String>, }
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct AddImplMethodOp {
107 pub target: String, pub method_def: String, pub position: InsertPosition,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct AddUseStatementOp {
114 pub use_path: String, pub position: InsertPosition,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct AddDeriveOp {
120 pub target_name: String, pub target_type: String, pub derives: Vec<String>, #[serde(default)]
124 pub where_filter: Option<String>, }
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub enum InsertPosition {
129 First,
130 Last,
131 After(String), Before(String), }
134
135#[derive(Debug, Serialize, Deserialize)]
136pub struct BatchSpec {
137 pub base_path: PathBuf,
138 pub operations: Vec<Operation>,
139}
140
141#[derive(Debug, Serialize, Deserialize, Clone)]
142pub struct NodeLocation {
143 pub line: usize,
144 pub column: usize,
145 pub end_line: usize,
146 pub end_column: usize,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct BackupNode {
152 pub node_type: String, pub identifier: String, pub original_content: String, pub location: NodeLocation,
156}
157
158#[derive(Debug)]
160pub struct ModificationResult {
161 pub changed: bool,
162 pub modified_nodes: Vec<BackupNode>,
163}
164
165#[derive(Debug, Serialize, Deserialize)]
167pub struct InspectResult {
168 pub file_path: String,
169 pub node_type: String, pub identifier: String, pub location: NodeLocation,
172 pub snippet: String, }
174
175#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct TransformOp {
178 pub node_type: String, pub name_filter: Option<String>, pub content_filter: Option<String>, pub action: TransformAction, }
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
186#[serde(tag = "type")]
187pub enum TransformAction {
188 Comment, Remove, Replace { with: String }, }