use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Operation {
AddStructField(AddStructFieldOp),
UpdateStructField(UpdateStructFieldOp),
RemoveStructField(RemoveStructFieldOp),
AddStructLiteralField(AddStructLiteralFieldOp),
AddEnumVariant(AddEnumVariantOp),
UpdateEnumVariant(UpdateEnumVariantOp),
RemoveEnumVariant(RemoveEnumVariantOp),
AddMatchArm(AddMatchArmOp),
UpdateMatchArm(UpdateMatchArmOp),
RemoveMatchArm(RemoveMatchArmOp),
AddImplMethod(AddImplMethodOp),
AddUseStatement(AddUseStatementOp),
AddDerive(AddDeriveOp),
Transform(TransformOp),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddStructFieldOp {
pub struct_name: String,
pub field_def: String, pub position: InsertPosition,
#[serde(default)]
pub literal_default: Option<String>, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateStructFieldOp {
pub struct_name: String,
pub field_def: String, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveStructFieldOp {
pub struct_name: String,
pub field_name: String, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddStructLiteralFieldOp {
pub struct_name: String,
pub field_def: String, pub position: InsertPosition,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddEnumVariantOp {
pub enum_name: String,
pub variant_def: String, pub position: InsertPosition,
#[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateEnumVariantOp {
pub enum_name: String,
pub variant_def: String, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveEnumVariantOp {
pub enum_name: String,
pub variant_name: String, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddMatchArmOp {
pub pattern: String, pub body: String, pub function_name: Option<String>, #[serde(default)]
pub auto_detect: bool, pub enum_name: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateMatchArmOp {
pub pattern: String, pub new_body: String, pub function_name: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveMatchArmOp {
pub pattern: String, pub function_name: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddImplMethodOp {
pub target: String, pub method_def: String, pub position: InsertPosition,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddUseStatementOp {
pub use_path: String, pub position: InsertPosition,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddDeriveOp {
pub target_name: String, pub target_type: String, pub derives: Vec<String>, #[serde(default)]
pub where_filter: Option<String>, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum InsertPosition {
First,
Last,
After(String), Before(String), }
#[derive(Debug, Serialize, Deserialize)]
pub struct BatchSpec {
pub base_path: PathBuf,
pub operations: Vec<Operation>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct NodeLocation {
pub line: usize,
pub column: usize,
pub end_line: usize,
pub end_column: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackupNode {
pub node_type: String, pub identifier: String, pub original_content: String, pub location: NodeLocation,
}
#[derive(Debug)]
pub struct ModificationResult {
pub changed: bool,
pub modified_nodes: Vec<BackupNode>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InspectResult {
pub file_path: String,
pub node_type: String, pub identifier: String, pub location: NodeLocation,
pub snippet: String, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransformOp {
pub node_type: String, pub name_filter: Option<String>, pub content_filter: Option<String>, pub action: TransformAction, }
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum TransformAction {
Comment, Remove, Replace { with: String }, }