ryo_mutations/basic/
const_type.rs1use ryo_symbol::SymbolId;
4
5use crate::Mutation;
6
7#[derive(Debug, Clone)]
9pub struct AddConstMutation {
10 pub symbol_id: SymbolId,
11 pub name: String,
12 pub ty: String,
13 pub value: String,
14 pub is_pub: bool,
15}
16
17impl AddConstMutation {
18 pub fn new(
19 symbol_id: SymbolId,
20 name: impl Into<String>,
21 ty: impl Into<String>,
22 value: impl Into<String>,
23 ) -> Self {
24 Self {
25 symbol_id,
26 name: name.into(),
27 ty: ty.into(),
28 value: value.into(),
29 is_pub: false,
30 }
31 }
32
33 pub fn public(mut self) -> Self {
34 self.is_pub = true;
35 self
36 }
37}
38
39impl Mutation for AddConstMutation {
40 fn describe(&self) -> String {
41 let vis = if self.is_pub { "pub " } else { "" };
42 format!(
43 "Add {}const {}: {} = {}",
44 vis, self.name, self.ty, self.value
45 )
46 }
47
48 fn mutation_type(&self) -> &'static str {
49 "AddConst"
50 }
51
52 fn box_clone(&self) -> Box<dyn Mutation> {
53 Box::new(self.clone())
54 }
55}
56
57#[derive(Debug, Clone)]
59pub struct RemoveConstMutation {
60 pub symbol_id: SymbolId,
61}
62
63impl RemoveConstMutation {
64 pub fn new(symbol_id: SymbolId) -> Self {
65 Self { symbol_id }
66 }
67}
68
69impl Mutation for RemoveConstMutation {
70 fn describe(&self) -> String {
71 format!("Remove const '{}'", self.symbol_id)
72 }
73
74 fn mutation_type(&self) -> &'static str {
75 "RemoveConst"
76 }
77
78 fn box_clone(&self) -> Box<dyn Mutation> {
79 Box::new(self.clone())
80 }
81}
82
83#[derive(Debug, Clone)]
85pub struct AddTypeAliasMutation {
86 pub symbol_id: SymbolId,
87 pub name: String,
88 pub ty: String,
89 pub is_pub: bool,
90}
91
92impl AddTypeAliasMutation {
93 pub fn new(symbol_id: SymbolId, name: impl Into<String>, ty: impl Into<String>) -> Self {
94 Self {
95 symbol_id,
96 name: name.into(),
97 ty: ty.into(),
98 is_pub: false,
99 }
100 }
101
102 pub fn public(mut self) -> Self {
103 self.is_pub = true;
104 self
105 }
106}
107
108impl Mutation for AddTypeAliasMutation {
109 fn describe(&self) -> String {
110 let vis = if self.is_pub { "pub " } else { "" };
111 format!("Add {}type {} = {}", vis, self.name, self.ty)
112 }
113
114 fn mutation_type(&self) -> &'static str {
115 "AddTypeAlias"
116 }
117
118 fn box_clone(&self) -> Box<dyn Mutation> {
119 Box::new(self.clone())
120 }
121}
122
123#[derive(Debug, Clone)]
125pub struct RemoveTypeAliasMutation {
126 pub symbol_id: SymbolId,
127}
128
129impl RemoveTypeAliasMutation {
130 pub fn new(symbol_id: SymbolId) -> Self {
131 Self { symbol_id }
132 }
133}
134
135impl Mutation for RemoveTypeAliasMutation {
136 fn describe(&self) -> String {
137 format!("Remove type alias '{}'", self.symbol_id)
138 }
139
140 fn mutation_type(&self) -> &'static str {
141 "RemoveTypeAlias"
142 }
143
144 fn box_clone(&self) -> Box<dyn Mutation> {
145 Box::new(self.clone())
146 }
147}