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