galvan_ast/item/
modifier.rs

1use crate::{AstNode, Span};
2use std::ops::Deref;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub struct Visibility {
6    pub kind: VisibilityKind,
7    span: Span,
8}
9
10impl Visibility {
11    pub fn new(kind: VisibilityKind, span: Span) -> Self {
12        Self { kind, span }
13    }
14
15    pub fn private() -> Self {
16        Self {
17            kind: VisibilityKind::Private,
18            span: Span::default(),
19        }
20    }
21
22    pub fn public() -> Self {
23        Self {
24            kind: VisibilityKind::Public,
25            span: Span::default(),
26        }
27    }
28
29    pub fn inherited() -> Self {
30        Self {
31            kind: VisibilityKind::Inherited,
32            span: Span::default(),
33        }
34    }
35}
36
37impl Deref for Visibility {
38    type Target = VisibilityKind;
39
40    fn deref(&self) -> &VisibilityKind {
41        &self.kind
42    }
43}
44
45impl AstNode for Visibility {
46    fn span(&self) -> Span {
47        self.span
48    }
49
50    fn print(&self, indent: usize) -> String {
51        let stringified = match self.kind {
52            VisibilityKind::Inherited => "inherited".to_string(),
53            VisibilityKind::Public => "pub".to_string(),
54            VisibilityKind::Private => "private".to_string(),
55        };
56
57        format!("{}{}", " ".repeat(indent), stringified)
58    }
59}
60
61#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
62pub enum VisibilityKind {
63    // Inherited usually means pub(crate)
64    #[default]
65    Inherited,
66    Public,
67    Private,
68}
69
70#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
71pub enum Ownership {
72    SharedOwned,
73    #[default]
74    Borrowed,
75    MutBorrowed,
76    UniqueOwned,
77    Ref,
78}
79
80#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
81pub enum Async {
82    Async,
83    // This usually means sync
84    #[default]
85    Inherited,
86    // This is not implemented but will be supported in future versions
87    Generic,
88}
89
90#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
91pub enum Const {
92    Const,
93    // This usually means not const
94    #[default]
95    Inherited,
96    // This is not implemented but will be supported in future versions
97    Generic,
98}