ryo-mutations 0.1.0

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

use ryo_source::pure::PureVis;
use ryo_symbol::SymbolId;

use crate::Mutation;

/// Change visibility of an item or struct field
///
/// Uses SymbolId for O(1) lookup. The SymbolId can point to:
/// - A top-level item (struct, enum, fn, const, etc.)
/// - A struct field
#[derive(Debug, Clone)]
pub struct ChangeVisibilityMutation {
    /// SymbolId of the target (required)
    pub symbol_id: SymbolId,
    /// New visibility
    pub to: PureVis,
}

impl ChangeVisibilityMutation {
    pub fn new(symbol_id: SymbolId, to: PureVis) -> Self {
        Self { symbol_id, to }
    }

    pub fn to_public(symbol_id: SymbolId) -> Self {
        Self::new(symbol_id, PureVis::Public)
    }

    pub fn to_private(symbol_id: SymbolId) -> Self {
        Self::new(symbol_id, PureVis::Private)
    }

    pub fn to_crate(symbol_id: SymbolId) -> Self {
        Self::new(symbol_id, PureVis::Crate)
    }
}

impl Mutation for ChangeVisibilityMutation {
    fn describe(&self) -> String {
        format!(
            "Change visibility of SymbolId({:?}) to {:?}",
            self.symbol_id, self.to
        )
    }

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

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