ryo-mutations 0.1.0

[experimental] Code transformation primitives for Rust source code
Documentation
//! Use statement mutations: AddUseMutation, RemoveUseMutation

use crate::Mutation;

/// Add a use statement to the file
#[derive(Debug, Clone)]
pub struct AddUseMutation {
    pub path: String, // e.g., "std::collections::HashMap"
}

impl AddUseMutation {
    pub fn new(path: impl Into<String>) -> Self {
        Self { path: path.into() }
    }
}

impl Mutation for AddUseMutation {
    fn describe(&self) -> String {
        format!("Add use {}", self.path)
    }

    fn mutation_type(&self) -> &'static str {
        "AddUse"
    }

    fn box_clone(&self) -> Box<dyn Mutation> {
        Box::new(self.clone())
    }
}

/// Remove a use statement from the file
#[derive(Debug, Clone)]
pub struct RemoveUseMutation {
    pub path: String,
}

impl RemoveUseMutation {
    pub fn new(path: impl Into<String>) -> Self {
        Self { path: path.into() }
    }
}

impl Mutation for RemoveUseMutation {
    fn describe(&self) -> String {
        format!("Remove use '{}'", self.path)
    }

    fn mutation_type(&self) -> &'static str {
        "RemoveUse"
    }

    fn box_clone(&self) -> Box<dyn Mutation> {
        Box::new(self.clone())
    }
}