use ryo_symbol::SymbolId;
use crate::Mutation;
#[derive(Debug, Clone)]
pub struct AddImplMutation {
pub parent: SymbolId,
pub target: String, pub trait_name: Option<String>, }
impl AddImplMutation {
pub fn new(parent: SymbolId, target: impl Into<String>) -> Self {
Self {
parent,
target: target.into(),
trait_name: None,
}
}
pub fn for_trait(mut self, trait_name: impl Into<String>) -> Self {
self.trait_name = Some(trait_name.into());
self
}
}
impl Mutation for AddImplMutation {
fn describe(&self) -> String {
match &self.trait_name {
Some(t) => format!("Add impl {} for {} to {}", t, self.target, self.parent),
None => format!("Add impl {} to {}", self.target, self.parent),
}
}
fn mutation_type(&self) -> &'static str {
"AddImpl"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}
#[derive(Debug, Clone)]
pub struct RemoveImplMutation {
pub symbol_id: SymbolId,
}
impl RemoveImplMutation {
pub fn new(symbol_id: SymbolId) -> Self {
Self { symbol_id }
}
}
impl Mutation for RemoveImplMutation {
fn describe(&self) -> String {
format!("Remove impl {}", self.symbol_id)
}
fn mutation_type(&self) -> &'static str {
"RemoveImpl"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}