use ryo_symbol::SymbolId;
use crate::Mutation;
#[derive(Debug, Clone)]
pub struct AddFieldMutation {
pub struct_id: SymbolId,
pub field_name: String,
pub field_type: String,
pub is_pub: bool,
}
impl AddFieldMutation {
pub fn new(
struct_id: SymbolId,
field_name: impl Into<String>,
field_type: impl Into<String>,
) -> Self {
Self {
struct_id,
field_name: field_name.into(),
field_type: field_type.into(),
is_pub: false,
}
}
pub fn public(mut self) -> Self {
self.is_pub = true;
self
}
}
impl Mutation for AddFieldMutation {
fn describe(&self) -> String {
let vis = if self.is_pub { "pub " } else { "" };
format!(
"Add {}{}: {} to struct {}",
vis, self.field_name, self.field_type, self.struct_id
)
}
fn mutation_type(&self) -> &'static str {
"AddField"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}
#[derive(Debug, Clone)]
pub struct RemoveFieldMutation {
pub struct_id: SymbolId,
pub field_name: String,
}
impl RemoveFieldMutation {
pub fn new(struct_id: SymbolId, field_name: impl Into<String>) -> Self {
Self {
struct_id,
field_name: field_name.into(),
}
}
}
impl Mutation for RemoveFieldMutation {
fn describe(&self) -> String {
format!("Remove field '{}' from {}", self.field_name, self.struct_id)
}
fn mutation_type(&self) -> &'static str {
"RemoveField"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}
#[derive(Debug, Clone)]
pub struct AddStructLiteralFieldMutation {
pub struct_id: SymbolId,
pub field_name: String,
pub value: String,
}
impl AddStructLiteralFieldMutation {
pub fn new(
struct_id: SymbolId,
field_name: impl Into<String>,
value: impl Into<String>,
) -> Self {
Self {
struct_id,
field_name: field_name.into(),
value: value.into(),
}
}
}
impl Mutation for AddStructLiteralFieldMutation {
fn describe(&self) -> String {
format!(
"Add field '{}' = {} to struct literals ({})",
self.field_name, self.value, self.struct_id
)
}
fn mutation_type(&self) -> &'static str {
"AddStructLiteralField"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}
#[derive(Debug, Clone)]
pub struct RemoveStructLiteralFieldMutation {
pub struct_id: SymbolId,
pub field_name: String,
}
impl RemoveStructLiteralFieldMutation {
pub fn new(struct_id: SymbolId, field_name: impl Into<String>) -> Self {
Self {
struct_id,
field_name: field_name.into(),
}
}
}
impl Mutation for RemoveStructLiteralFieldMutation {
fn describe(&self) -> String {
format!(
"Remove field '{}' from struct literals ({})",
self.field_name, self.struct_id
)
}
fn mutation_type(&self) -> &'static str {
"RemoveStructLiteralField"
}
fn box_clone(&self) -> Box<dyn Mutation> {
Box::new(self.clone())
}
}