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    pub const fn is_deprecated(self) -> bool {
46        self.contains(Self::DEPRECATED)
47    }
48
49    #[inline]
50    pub const fn is_abstract(self) -> bool {
51        self.contains(Self::ABSTRACT)
52    }
53
54    #[inline]
55    pub const fn is_final(self) -> bool {
56        self.contains(Self::FINAL)
57    }
58
59    #[inline]
60    pub const fn has_yield(self) -> bool {
61        self.contains(Self::HAS_YIELD)
62    }
63
64    #[inline]
65    pub const fn must_use(self) -> bool {
66        self.contains(Self::MUST_USE)
67    }
68
69    #[inline]
70    pub const fn is_pure(self) -> bool {
71        self.contains(Self::PURE)
72    }
73
74    #[inline]
75    pub const fn has_consistent_constructor(self) -> bool {
76        self.contains(Self::CONSISTENT_CONSTRUCTOR)
77    }
78
79    #[inline]
80    pub const fn has_consistent_templates(self) -> bool {
81        self.contains(Self::CONSISTENT_TEMPLATES)
82    }
83
84    #[inline]
85    pub const fn is_user_defined(self) -> bool {
86        self.contains(Self::USER_DEFINED)
87    }
88
89    #[inline]
90    pub const fn is_built_in(self) -> bool {
91        self.contains(Self::BUILTIN)
92    }
93
94    #[inline]
95    pub const fn is_internal(self) -> bool {
96        self.contains(Self::INTERNAL)
97    }
98
99    #[inline]
100    pub const fn is_populated(self) -> bool {
101        self.contains(Self::POPULATED)
102    }
103
104    #[inline]
105    pub const fn is_readonly(self) -> bool {
106        self.contains(Self::READONLY)
107    }
108
109    #[inline]
110    pub const fn is_writeonly(self) -> bool {
111        self.contains(Self::WRITEONLY)
112    }
113
114    #[inline]
115    pub const fn is_enum_interface(self) -> bool {
116        self.contains(Self::ENUM_INTERFACE)
117    }
118
119    #[inline]
120    pub const fn is_unchecked(self) -> bool {
121        self.contains(Self::UNCHECKED)
122    }
123
124    #[inline]
125    pub const fn ignore_nullable_return(self) -> bool {
126        self.contains(Self::IGNORE_NULLABLE_RETURN)
127    }
128
129    #[inline]
130    pub const fn ignore_falsable_return(self) -> bool {
131        self.contains(Self::IGNORE_FALSABLE_RETURN)
132    }
133
134    #[inline]
135    pub const fn inherits_docs(self) -> bool {
136        self.contains(Self::INHERITS_DOCS)
137    }
138
139    #[inline]
140    pub const fn forbids_named_arguments(self) -> bool {
141        self.contains(Self::NO_NAMED_ARGUMENTS)
142    }
143
144    #[inline]
145    pub const fn has_throw(self) -> bool {
146        self.contains(Self::HAS_THROW)
147    }
148
149    #[inline]
150    pub const fn is_backed_enum_case(self) -> bool {
151        self.contains(Self::BACKED_ENUM_CASE)
152    }
153
154    #[inline]
155    pub const fn is_unit_enum_case(self) -> bool {
156        self.contains(Self::UNIT_ENUM_CASE)
157    }
158
159    #[inline]
160    pub const fn is_by_reference(self) -> bool {
161        self.contains(Self::BY_REFERENCE)
162    }
163
164    #[inline]
165    pub const fn is_variadic(self) -> bool {
166        self.contains(Self::VARIADIC)
167    }
168
169    #[inline]
170    pub const fn is_promoted_property(self) -> bool {
171        self.contains(Self::PROMOTED_PROPERTY)
172    }
173
174    #[inline]
175    pub const fn has_default(self) -> bool {
176        self.contains(Self::HAS_DEFAULT)
177    }
178
179    #[inline]
180    pub const fn is_virtual_property(self) -> bool {
181        self.contains(Self::VIRTUAL_PROPERTY)
182    }
183
184    #[inline]
185    pub const fn is_magic_property(self) -> bool {
186        self.contains(Self::MAGIC_PROPERTY)
187    }
188
189    #[inline]
190    pub const fn is_magic_method(self) -> bool {
191        self.contains(Self::MAGIC_METHOD)
192    }
193
194    #[inline]
195    pub const fn is_asymmetric_property(self) -> bool {
196        self.contains(Self::ASYMMETRIC_PROPERTY)
197    }
198
199    #[inline]
200    pub const fn is_static(self) -> bool {
201        self.contains(Self::STATIC)
202    }
203}