ryo-mutations 0.1.0

[experimental] Code transformation primitives for Rust source code
Documentation
//! Rename mutation

use ryo_source::pure::PureFile;
use ryo_symbol::SymbolId;

use crate::{Mutation, ValidationResult};

/// Rename a symbol across the file
///
/// **Note**: `symbol_id` is required for O(1) lookup.
#[derive(Debug, Clone)]
pub struct RenameMutation {
    /// SymbolId - required for O(1) lookup
    pub symbol_id: SymbolId,
    /// New name to rename to
    pub to: String,
}

impl RenameMutation {
    /// Create a new RenameMutation with required symbol_id
    pub fn new(symbol_id: SymbolId, to: impl Into<String>) -> Self {
        Self {
            symbol_id,
            to: to.into(),
        }
    }
}

impl Mutation for RenameMutation {
    fn validate(&self, _file: &PureFile) -> ValidationResult {
        // Validation is minimal since we rely on symbol_id (O(1) lookup)
        // Actual validation happens during AST execution via ASTRegApply
        ValidationResult::new()
    }

    fn describe(&self) -> String {
        format!("Rename symbol {:?} to '{}'", self.symbol_id, self.to)
    }

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

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