mago_codex/metadata/
flags.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4bitflags::bitflags! {
5    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
6    pub struct MetadataFlags: u64 {
7        const ABSTRACT                  = 1 << 0;
8        const FINAL                     = 1 << 1;
9        const IMMUTABLE                 = 1 << 2;
10        const READONLY                  = 1 << 3;
11        const DEPRECATED                = 1 << 4;
12        const ENUM_INTERFACE            = 1 << 5;
13        const POPULATED                 = 1 << 6;
14        const INTERNAL                  = 1 << 7;
15        const MUTATION_FREE             = 1 << 8;
16        const EXTERNAL_MUTATION_FREE    = 1 << 9;
17        const ALLOWS_PRIVATE_MUTATION   = 1 << 10;
18        const CONSISTENT_CONSTRUCTOR    = 1 << 11;
19        const CONSISTENT_TEMPLATES      = 1 << 12;
20        const UNCHECKED                 = 1 << 13;
21        const USER_DEFINED              = 1 << 14;
22        const BUILTIN                   = 1 << 15;
23        const HAS_YIELD                 = 1 << 16;
24        const MUST_USE                  = 1 << 17;
25        const HAS_THROW                 = 1 << 18;
26        const PURE                      = 1 << 19;
27        const IGNORE_NULLABLE_RETURN    = 1 << 20;
28        const IGNORE_FALSABLE_RETURN    = 1 << 21;
29        const INHERITS_DOCS             = 1 << 22;
30        const NO_NAMED_ARGUMENTS        = 1 << 23;
31        const BACKED_ENUM_CASE          = 1 << 24;
32        const UNIT_ENUM_CASE            = 1 << 25;
33        const BY_REFERENCE              = 1 << 26;
34        const VARIADIC                  = 1 << 27;
35        const PROMOTED_PROPERTY         = 1 << 28;
36        const HAS_DEFAULT               = 1 << 29;
37        const VIRTUAL_PROPERTY          = 1 << 30;
38        const ASYMMETRIC_PROPERTY       = 1 << 31;
39        const STATIC                    = 1 << 32;
40    }
41}
42
43// example: helper methods for extra readability
44impl MetadataFlags {
45    #[inline]
46    pub const fn is_deprecated(self) -> bool {
47        self.contains(Self::DEPRECATED)
48    }
49
50    #[inline]
51    pub const fn is_abstract(self) -> bool {
52        self.contains(Self::ABSTRACT)
53    }
54
55    #[inline]
56    pub const fn is_final(self) -> bool {
57        self.contains(Self::FINAL)
58    }
59
60    #[inline]
61    pub const fn has_yield(self) -> bool {
62        self.contains(Self::HAS_YIELD)
63    }
64
65    #[inline]
66    pub const fn must_use(self) -> bool {
67        self.contains(Self::MUST_USE)
68    }
69
70    #[inline]
71    pub const fn is_pure(self) -> bool {
72        self.contains(Self::PURE)
73    }
74
75    #[inline]
76    pub const fn is_mutation_free(self) -> bool {
77        self.contains(Self::MUTATION_FREE)
78    }
79
80    #[inline]
81    pub const fn is_external_mutation_free(self) -> bool {
82        self.contains(Self::EXTERNAL_MUTATION_FREE)
83    }
84
85    #[inline]
86    pub const fn allows_private_mutation(self) -> bool {
87        self.contains(Self::ALLOWS_PRIVATE_MUTATION)
88    }
89
90    #[inline]
91    pub const fn has_consistent_constructor(self) -> bool {
92        self.contains(Self::CONSISTENT_CONSTRUCTOR)
93    }
94
95    #[inline]
96    pub const fn has_consistent_templates(self) -> bool {
97        self.contains(Self::CONSISTENT_TEMPLATES)
98    }
99
100    #[inline]
101    pub const fn is_user_defined(self) -> bool {
102        self.contains(Self::USER_DEFINED)
103    }
104
105    #[inline]
106    pub const fn is_built_in(self) -> bool {
107        self.contains(Self::BUILTIN)
108    }
109
110    #[inline]
111    pub const fn is_internal(self) -> bool {
112        self.contains(Self::INTERNAL)
113    }
114
115    #[inline]
116    pub const fn is_populated(self) -> bool {
117        self.contains(Self::POPULATED)
118    }
119
120    #[inline]
121    pub const fn is_readonly(self) -> bool {
122        self.contains(Self::READONLY)
123    }
124
125    #[inline]
126    pub const fn is_immutable(self) -> bool {
127        self.contains(Self::IMMUTABLE)
128    }
129
130    #[inline]
131    pub const fn is_enum_interface(self) -> bool {
132        self.contains(Self::ENUM_INTERFACE)
133    }
134
135    #[inline]
136    pub const fn is_unchecked(self) -> bool {
137        self.contains(Self::UNCHECKED)
138    }
139
140    #[inline]
141    pub const fn ignore_nullable_return(self) -> bool {
142        self.contains(Self::IGNORE_NULLABLE_RETURN)
143    }
144
145    #[inline]
146    pub const fn ignore_falsable_return(self) -> bool {
147        self.contains(Self::IGNORE_FALSABLE_RETURN)
148    }
149
150    #[inline]
151    pub const fn inherits_docs(self) -> bool {
152        self.contains(Self::INHERITS_DOCS)
153    }
154
155    #[inline]
156    pub const fn forbids_named_arguments(self) -> bool {
157        self.contains(Self::NO_NAMED_ARGUMENTS)
158    }
159
160    #[inline]
161    pub const fn has_throw(self) -> bool {
162        self.contains(Self::HAS_THROW)
163    }
164
165    #[inline]
166    pub const fn is_backed_enum_case(self) -> bool {
167        self.contains(Self::BACKED_ENUM_CASE)
168    }
169
170    #[inline]
171    pub const fn is_unit_enum_case(self) -> bool {
172        self.contains(Self::UNIT_ENUM_CASE)
173    }
174
175    #[inline]
176    pub const fn is_by_reference(self) -> bool {
177        self.contains(Self::BY_REFERENCE)
178    }
179
180    #[inline]
181    pub const fn is_variadic(self) -> bool {
182        self.contains(Self::VARIADIC)
183    }
184
185    #[inline]
186    pub const fn is_promoted_property(self) -> bool {
187        self.contains(Self::PROMOTED_PROPERTY)
188    }
189
190    #[inline]
191    pub const fn has_default(self) -> bool {
192        self.contains(Self::HAS_DEFAULT)
193    }
194
195    #[inline]
196    pub const fn is_virtual_property(self) -> bool {
197        self.contains(Self::VIRTUAL_PROPERTY)
198    }
199
200    #[inline]
201    pub const fn is_asymmetric_property(self) -> bool {
202        self.contains(Self::ASYMMETRIC_PROPERTY)
203    }
204
205    #[inline]
206    pub const fn is_static(self) -> bool {
207        self.contains(Self::STATIC)
208    }
209}