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 RenameEnumVariant(RenameEnumVariantOp),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct AddStructFieldOp {
26 pub struct_name: String,
27 pub field_def: String, pub position: InsertPosition,
29 #[serde(default)]
30 pub literal_default: Option<String>, #[serde(default)]
32 pub where_filter: Option<String>, }
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct UpdateStructFieldOp {
37 pub struct_name: String,
38 pub field_def: String, #[serde(default)]
40 pub where_filter: Option<String>, }
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct RemoveStructFieldOp {
45 pub struct_name: String,
46 pub field_name: String, #[serde(default)]
48 pub where_filter: Option<String>, }
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct AddStructLiteralFieldOp {
53 pub struct_name: String,
54 pub field_def: String, pub position: InsertPosition,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct AddEnumVariantOp {
60 pub enum_name: String,
61 pub variant_def: String, pub position: InsertPosition,
63 #[serde(default)]
64 pub where_filter: Option<String>, }
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct UpdateEnumVariantOp {
69 pub enum_name: String,
70 pub variant_def: String, #[serde(default)]
72 pub where_filter: Option<String>, }
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct RemoveEnumVariantOp {
77 pub enum_name: String,
78 pub variant_name: String, #[serde(default)]
80 pub where_filter: Option<String>, }
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct AddMatchArmOp {
85 pub pattern: String, pub body: String, pub function_name: Option<String>, #[serde(default)]
89 pub auto_detect: bool, pub enum_name: Option<String>, }
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct UpdateMatchArmOp {
95 pub pattern: String, pub new_body: String, pub function_name: Option<String>, }
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct RemoveMatchArmOp {
102 pub pattern: String, pub function_name: Option<String>, }
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct AddImplMethodOp {
108 pub target: String, pub method_def: String, pub position: InsertPosition,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct AddUseStatementOp {
115 pub use_path: String, pub position: InsertPosition,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct AddDeriveOp {
121 pub target_name: String, pub target_type: String, pub derives: Vec<String>, #[serde(default)]
125 pub where_filter: Option<String>, }
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
129pub enum InsertPosition {
130 First,
131 Last,
132 After(String), Before(String), }
135
136#[derive(Debug, Serialize, Deserialize)]
137pub struct BatchSpec {
138 pub base_path: PathBuf,
139 pub operations: Vec<Operation>,
140}
141
142#[derive(Debug, Serialize, Deserialize, Clone)]
143pub struct NodeLocation {
144 pub line: usize,
145 pub column: usize,
146 pub end_line: usize,
147 pub end_column: usize,
148}
149
150#[derive(Debug, Clone, Serialize, Deserialize)]
152pub struct BackupNode {
153 pub node_type: String, pub identifier: String, pub original_content: String, pub location: NodeLocation,
157}
158
159#[derive(Debug)]
161pub struct ModificationResult {
162 pub changed: bool,
163 pub modified_nodes: Vec<BackupNode>,
164}
165
166#[derive(Debug, Serialize, Deserialize)]
168pub struct InspectResult {
169 pub file_path: String,
170 pub node_type: String, pub identifier: String, pub location: NodeLocation,
173 pub snippet: String, }
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct TransformOp {
179 pub node_type: String, pub name_filter: Option<String>, pub content_filter: Option<String>, pub action: TransformAction, }
184
185#[derive(Debug, Clone, Serialize, Deserialize)]
187#[serde(tag = "type")]
188pub enum TransformAction {
189 Comment, Remove, Replace { with: String }, }
193
194#[derive(Debug, Clone, Serialize, Deserialize)]
196pub struct RenameEnumVariantOp {
197 pub enum_name: String, pub old_variant: String, pub new_variant: String, }