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}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct AddStructFieldOp {
24 pub struct_name: String,
25 pub field_def: String, pub position: InsertPosition,
27 #[serde(default)]
28 pub literal_default: Option<String>, #[serde(default)]
30 pub where_filter: Option<String>, }
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct UpdateStructFieldOp {
35 pub struct_name: String,
36 pub field_def: String, #[serde(default)]
38 pub where_filter: Option<String>, }
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct RemoveStructFieldOp {
43 pub struct_name: String,
44 pub field_name: String, #[serde(default)]
46 pub where_filter: Option<String>, }
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct AddStructLiteralFieldOp {
51 pub struct_name: String,
52 pub field_def: String, pub position: InsertPosition,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct AddEnumVariantOp {
58 pub enum_name: String,
59 pub variant_def: String, pub position: InsertPosition,
61 #[serde(default)]
62 pub where_filter: Option<String>, }
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct UpdateEnumVariantOp {
67 pub enum_name: String,
68 pub variant_def: String, #[serde(default)]
70 pub where_filter: Option<String>, }
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct RemoveEnumVariantOp {
75 pub enum_name: String,
76 pub variant_name: String, #[serde(default)]
78 pub where_filter: Option<String>, }
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct AddMatchArmOp {
83 pub pattern: String, pub body: String, pub function_name: Option<String>, #[serde(default)]
87 pub auto_detect: bool, pub enum_name: Option<String>, }
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct UpdateMatchArmOp {
93 pub pattern: String, pub new_body: String, pub function_name: Option<String>, }
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct RemoveMatchArmOp {
100 pub pattern: String, pub function_name: Option<String>, }
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct AddImplMethodOp {
106 pub target: String, pub method_def: String, pub position: InsertPosition,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct AddUseStatementOp {
113 pub use_path: String, pub position: InsertPosition,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct AddDeriveOp {
119 pub target_name: String, pub target_type: String, pub derives: Vec<String>, #[serde(default)]
123 pub where_filter: Option<String>, }
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub enum InsertPosition {
128 First,
129 Last,
130 After(String), Before(String), }
133
134#[derive(Debug, Serialize, Deserialize)]
135pub struct BatchSpec {
136 pub base_path: PathBuf,
137 pub operations: Vec<Operation>,
138}
139
140#[derive(Debug, Serialize, Deserialize, Clone)]
141pub struct NodeLocation {
142 pub line: usize,
143 pub column: usize,
144 pub end_line: usize,
145 pub end_column: usize,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct BackupNode {
151 pub node_type: String, pub identifier: String, pub original_content: String, pub location: NodeLocation,
155}
156
157#[derive(Debug)]
159pub struct ModificationResult {
160 pub changed: bool,
161 pub modified_nodes: Vec<BackupNode>,
162}
163
164#[derive(Debug, Serialize, Deserialize)]
166pub struct InspectResult {
167 pub file_path: String,
168 pub node_type: String, pub identifier: String, pub location: NodeLocation,
171 pub snippet: String, }