Skip to main content

ryo_mutations/basic/
derive.rs

1//! Derive mutations: AddDeriveMutation, RemoveDeriveMutation
2
3use ryo_symbol::SymbolId;
4
5use crate::Mutation;
6
7/// Add a derive macro to a struct or enum
8///
9/// Uses SymbolId for O(1) lookup.
10#[derive(Debug, Clone)]
11pub struct AddDeriveMutation {
12    /// SymbolId of the target type (required)
13    pub symbol_id: SymbolId,
14    pub derives: Vec<String>,
15}
16
17impl AddDeriveMutation {
18    pub fn new(symbol_id: SymbolId, derives: Vec<String>) -> Self {
19        Self { symbol_id, derives }
20    }
21
22    pub fn single(symbol_id: SymbolId, derive: impl Into<String>) -> Self {
23        Self {
24            symbol_id,
25            derives: vec![derive.into()],
26        }
27    }
28}
29
30impl Mutation for AddDeriveMutation {
31    fn describe(&self) -> String {
32        format!(
33            "Add #[derive({})] to SymbolId({})",
34            self.derives.join(", "),
35            self.symbol_id
36        )
37    }
38
39    fn mutation_type(&self) -> &'static str {
40        "AddDerive"
41    }
42
43    fn box_clone(&self) -> Box<dyn Mutation> {
44        Box::new(self.clone())
45    }
46}
47
48/// Remove a derive macro from a struct or enum
49///
50/// Uses SymbolId for O(1) lookup.
51#[derive(Debug, Clone)]
52pub struct RemoveDeriveMutation {
53    /// SymbolId of the target type (required)
54    pub symbol_id: SymbolId,
55    pub derives: Vec<String>,
56}
57
58impl RemoveDeriveMutation {
59    pub fn new(symbol_id: SymbolId, derives: Vec<String>) -> Self {
60        Self { symbol_id, derives }
61    }
62
63    pub fn single(symbol_id: SymbolId, derive: impl Into<String>) -> Self {
64        Self {
65            symbol_id,
66            derives: vec![derive.into()],
67        }
68    }
69}
70
71impl Mutation for RemoveDeriveMutation {
72    fn describe(&self) -> String {
73        format!(
74            "Remove #[derive({})] from SymbolId({})",
75            self.derives.join(", "),
76            self.symbol_id
77        )
78    }
79
80    fn mutation_type(&self) -> &'static str {
81        "RemoveDerive"
82    }
83
84    fn box_clone(&self) -> Box<dyn Mutation> {
85        Box::new(self.clone())
86    }
87}