ryo_mutations/basic/
impl_block.rs1use ryo_symbol::SymbolId;
4
5use crate::Mutation;
6
7#[derive(Debug, Clone)]
9pub struct AddImplMutation {
10 pub parent: SymbolId,
12 pub target: String, pub trait_name: Option<String>, }
15
16impl AddImplMutation {
17 pub fn new(parent: SymbolId, target: impl Into<String>) -> Self {
18 Self {
19 parent,
20 target: target.into(),
21 trait_name: None,
22 }
23 }
24
25 pub fn for_trait(mut self, trait_name: impl Into<String>) -> Self {
26 self.trait_name = Some(trait_name.into());
27 self
28 }
29}
30
31impl Mutation for AddImplMutation {
32 fn describe(&self) -> String {
33 match &self.trait_name {
34 Some(t) => format!("Add impl {} for {} to {}", t, self.target, self.parent),
35 None => format!("Add impl {} to {}", self.target, self.parent),
36 }
37 }
38
39 fn mutation_type(&self) -> &'static str {
40 "AddImpl"
41 }
42
43 fn box_clone(&self) -> Box<dyn Mutation> {
44 Box::new(self.clone())
45 }
46}
47
48#[derive(Debug, Clone)]
50pub struct RemoveImplMutation {
51 pub symbol_id: SymbolId,
52}
53
54impl RemoveImplMutation {
55 pub fn new(symbol_id: SymbolId) -> Self {
56 Self { symbol_id }
57 }
58}
59
60impl Mutation for RemoveImplMutation {
61 fn describe(&self) -> String {
62 format!("Remove impl {}", self.symbol_id)
63 }
64
65 fn mutation_type(&self) -> &'static str {
66 "RemoveImpl"
67 }
68
69 fn box_clone(&self) -> Box<dyn Mutation> {
70 Box::new(self.clone())
71 }
72}