Skip to main content

ryo_mutations/basic/
rename.rs

1//! Rename mutation
2
3use ryo_source::pure::PureFile;
4use ryo_symbol::SymbolId;
5
6use crate::{Mutation, ValidationResult};
7
8/// Rename a symbol across the file
9///
10/// **Note**: `symbol_id` is required for O(1) lookup.
11#[derive(Debug, Clone)]
12pub struct RenameMutation {
13    /// SymbolId - required for O(1) lookup
14    pub symbol_id: SymbolId,
15    /// New name to rename to
16    pub to: String,
17}
18
19impl RenameMutation {
20    /// Create a new RenameMutation with required symbol_id
21    pub fn new(symbol_id: SymbolId, to: impl Into<String>) -> Self {
22        Self {
23            symbol_id,
24            to: to.into(),
25        }
26    }
27}
28
29impl Mutation for RenameMutation {
30    fn validate(&self, _file: &PureFile) -> ValidationResult {
31        // Validation is minimal since we rely on symbol_id (O(1) lookup)
32        // Actual validation happens during AST execution via ASTRegApply
33        ValidationResult::new()
34    }
35
36    fn describe(&self) -> String {
37        format!("Rename symbol {:?} to '{}'", self.symbol_id, self.to)
38    }
39
40    fn mutation_type(&self) -> &'static str {
41        "Rename"
42    }
43
44    fn box_clone(&self) -> Box<dyn Mutation> {
45        Box::new(self.clone())
46    }
47}