Skip to main content

ryo_mutations/basic/
visibility.rs

1//! Visibility mutation
2
3use ryo_source::pure::PureVis;
4use ryo_symbol::SymbolId;
5
6use crate::Mutation;
7
8/// Change visibility of an item or struct field
9///
10/// Uses SymbolId for O(1) lookup. The SymbolId can point to:
11/// - A top-level item (struct, enum, fn, const, etc.)
12/// - A struct field
13#[derive(Debug, Clone)]
14pub struct ChangeVisibilityMutation {
15    /// SymbolId of the target (required)
16    pub symbol_id: SymbolId,
17    /// New visibility
18    pub to: PureVis,
19}
20
21impl ChangeVisibilityMutation {
22    pub fn new(symbol_id: SymbolId, to: PureVis) -> Self {
23        Self { symbol_id, to }
24    }
25
26    pub fn to_public(symbol_id: SymbolId) -> Self {
27        Self::new(symbol_id, PureVis::Public)
28    }
29
30    pub fn to_private(symbol_id: SymbolId) -> Self {
31        Self::new(symbol_id, PureVis::Private)
32    }
33
34    pub fn to_crate(symbol_id: SymbolId) -> Self {
35        Self::new(symbol_id, PureVis::Crate)
36    }
37}
38
39impl Mutation for ChangeVisibilityMutation {
40    fn describe(&self) -> String {
41        format!(
42            "Change visibility of SymbolId({:?}) to {:?}",
43            self.symbol_id, self.to
44        )
45    }
46
47    fn mutation_type(&self) -> &'static str {
48        "ChangeVisibility"
49    }
50
51    fn box_clone(&self) -> Box<dyn Mutation> {
52        Box::new(self.clone())
53    }
54}