microcad_lang/syntax/
visibility.rs

1// Copyright © 2024-2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Visibility of an entity.
5
6use crate::syntax::*;
7
8/// Visibility of an entity.
9///
10/// This is used to determine if an entity is public or private.
11/// By default, entities are private.
12#[derive(Clone, Default, PartialEq)]
13pub enum Visibility {
14    /// Private visibility
15    #[default]
16    Private,
17    /// Private visibility within a given use all reference.
18    PrivateUse(QualifiedName),
19    /// Public visibility
20    Public,
21    /// Mark symbol for deletion {used internally while resolving)
22    Deleted,
23}
24
25impl std::fmt::Display for Visibility {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            Visibility::Private => Ok(()),
29            Visibility::PrivateUse(_) => Ok(()),
30            Visibility::Public => write!(f, "pub "),
31            Visibility::Deleted => write!(f, "(deleted) "),
32        }
33    }
34}
35
36impl std::fmt::Debug for Visibility {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            Visibility::Private => Ok(()),
40            Visibility::PrivateUse(name) => write!(f, "«{name}» "),
41            Visibility::Public => write!(f, "pub "),
42            Visibility::Deleted => write!(f, "❌ "),
43        }
44    }
45}