Skip to main content

miden_assembly_syntax/ast/
visibility.rs

1use core::fmt;
2
3// ITEM VISIBILITY
4// ================================================================================================
5
6/// Represents the visibility of an item (procedure, constant, etc.) globally.
7#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[repr(u8)]
10pub enum Visibility {
11    /// The item is visible outside its defining module
12    Public = 0,
13    /// The item is visible only within its defining module
14    #[default]
15    Private = 1,
16}
17
18impl fmt::Display for Visibility {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        if self.is_public() { f.write_str("pub") } else { Ok(()) }
21    }
22}
23
24impl Visibility {
25    /// Returns true if the current item has public visibility
26    pub fn is_public(&self) -> bool {
27        matches!(self, Self::Public)
28    }
29}