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#[repr(u8)]
9pub enum Visibility {
10 /// The item is visible outside its defining module
11 Public = 0,
12 /// The item is visible only within its defining module
13 #[default]
14 Private = 1,
15 /// The item is visible outside its module, but is not exported from the package.
16 Internal = 2,
17}
18
19impl fmt::Display for Visibility {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 match self {
22 Self::Public => f.write_str("pub"),
23 Self::Internal => f.write_str("pub(package)"),
24 Self::Private => Ok(()),
25 }
26 }
27}
28
29impl Visibility {
30 /// Returns true if the item is visible outside its defining module
31 pub fn is_public(&self) -> bool {
32 matches!(self, Self::Public | Self::Internal)
33 }
34
35 /// Returns true if the item is eligible for export from the package.
36 pub fn is_exported(&self) -> bool {
37 matches!(self, Self::Public)
38 }
39}