1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//! Vexillo is a crate for creating bitflags types.
//!
//! # Example
//! ````````rust,no_run
//!
//! vexillo::flags! {
//! // Specify struct visibility, struct name, masks visibility, and masks type.
//! pub struct MyFlags(pub [u16]);
//! // Although it is defined as a tuple struct, the resulting
//! // struct looks like this:
//! // #[repr(transparent)]
//! // #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
//! // pub struct MyFlags {
//! // pub masks: [u16; _], // where _ is the mask count.
//! // }
//! // Minimal requirement:
//! // `struct MyFlags;`, becomes `struct MyFlags([u32]);`
//! // Declare flag constants.
//! // Specify visibility of constants (use priv for private).
//! pub const {
//! // This will be a public flag because the const block is public.
//! FLAG0
//! GROUP0: [
//! // use `+` to add flags, `-` to remove them.
//! // Order of additions and removals does not matter,
//! // they will be reordered so that additions come before removals.
//! + FLAG0
//! FLAG1
//! FLAG2
//! FLAG3
//! ]
//! // This will create a constant named GROUP1 with the following flags:
//! // FLAG3
//! // FLAG4
//! // FLAG5
//! // FLAG6
//! GROUP1: [
//! + GROUP0
//! // Use `|` to join flags together.
//! - FLAG0
//! | FLAG1
//! | FLAG2
//! FLAG4
//! SUBGROUP: [
//! FLAG5
//! FLAG6
//! ]
//! ]
//! }
//! }
//!
//! assert!(
//! MyFlags::SUBGROUP.has_all(MyFlags::union(&[
//! MyFlags::FLAG5,
//! MyFlags::FLAG6,
//! ]))
//! );
//!
//! assert!(
//! MyFlags::GROUP1.has_all(MyFlags::union(&[
//! MyFlags::FLAG3,
//! MyFlags::FLAG4,
//! MyFlags::FLAG5,
//! MyFlags::FLAG6,
//! MyFlags::SUBGROUP,
//! ]))
//! &&
//! MyFlags::GROUP1.has_none(MyFlags::union(&[
//! MyFlags::FLAG0,
//! MyFlags::FLAG1,
//! MyFlags::FLAG2,
//! ]))
//! );
//! assert_eq!(MyFlags::TOTAL_FLAG_COUNT, 10);
//! assert_eq!(MyFlags::SINGLE_FLAG_COUNT, 7);
//! assert_eq!(MyFlags::GROUP_FLAG_COUNT, 3);
//!
//! ````````
//! ___
pub use *;
/// Create a bitflags type.
///
/// # Example
/// ```
/// flags! {
/// // Define type with `vis struct Name(vis [FlagIntType]);
/// // FlagIntType must be one of the following: u8, u16, u32, or u64.
/// // The FlagIntType determines the type to use for bit masks. `vis` determines
/// // visibility. Default visibility is private.
/// /// Example flags struct.
/// pub struct ExampleFlags(pub [u64]);
/// // Optional:
/// override {
/// // Change name or visibility of builtin functions/constants.
/// // You can not remove these builtin functions as they might be necessary for certain
/// // functionality to work. You can hide them by modifying their visibility.
/// // Creation
/// // vis original_name: new_name
/// // use priv to make it private.
/// // no visibility modifier means that it will use the default visibility, which is `pub` for
/// // most of the builtin functions.
/// pub none: empty
/// pub all: full
/// pub new: create
/// pub union
/// pub union_without
/// pub try_find
/// pub find
/// pub find_or
/// pub find_or_none
/// pub count_ones
/// pub count_zeros
/// pub add
/// pub add_all
/// pub remove
/// pub remove_all
/// pub with
/// pub with_all
/// pub without
/// pub without_all
/// pub get
/// pub set
/// pub from_index
/// pub has_all
/// pub has_none
/// pub has_any
/// pub masks
/// pub masks_mut
/// pub into_inner
/// pub as_bytes
/// pub as_mut_bytes
/// pub to_be_bytes
/// pub to_le_bytes
/// pub to_ne_bytes
/// pub from_be_bytes
/// pub from_le_bytes
/// pub from_ne_bytes
/// // Bitwise logic
/// pub not
/// pub and
/// pub or
/// pub nand
/// pub nor
/// pub xor
/// pub xnor
/// pub imply
/// pub nimply
/// // Comparisons
/// pub eq
/// pub ne
/// }
/// pub const {
/// FLAG0
/// // Declaration
/// priv DECLARATION
/// // Group
/// #[doc = "hello, world"]
/// pub GROUP: [
/// + FLAG0
/// ALPHA
/// BETA
/// CAPPA
/// ]
/// // Empty group to specify no flags set.
/// pub TEST: []
/// pub FLAGS: [
/// // [vis] <identifier> is a flag declaration. These flags will be assigned a single bit, in the order that they appear.
/// APPLE
/// BANANA
/// STRAWBERRY
/// pub FRUIT: [
/// // Use + to add flags, use | to join them together.
/// + APPLE | BANANA | STRAWBERRY
/// // Alternatively, it looks nice when you put them all on the same line:
/// // + APPLE
/// // | BANANA
/// // | STRAWBERRY
/// // Use - to remove flags.
/// // This removes BANANA and STRAWBERRY.
/// - BANANA
/// | STRAWBERRY
/// ]
/// // Alternatively, you could have declared the fruit inside of the FRUIT group.
/// pub PUBLIC: [
/// // All flags in PUBLIC will be pub unless otherwise specified.
/// // These are all public single flag consts.
/// ONE
/// TWO
/// THREE
/// ]
/// ]
/// // You can bind a flag to another name with this simple trick:
/// pub FULL: [+ALL]
/// }
/// }
/// ```
flags!
/*
// Builtin flag constants:
// - `NONE` (No bits set)
// - `ALL` (All used bits set)
// Builtin constants in the form of functions, so as to not pollute the constants.
// - `flag_count` (Number of single bit flags)
// - `mask_count` (The number of masks in the masks array)
// - `mask_bit_size` (The size in bits of the mask type)
// - `index_order_flags` (An array of single flags ordered by index ascending)
// pub const index_order_flags() -> &'static [(&'static str, Self)]
// - `bit_size_order_flags` (An array of flags ordered by bit count descending)
// pub const bit_size_order_flags() -> &'static [(&'static str, Self)]
// - `lowercase_names` (An array of lowercase names for single flags in the order of their index)
// - `uppercase_names` (An array of uppercase names for single flags in the order of their index)
Functions that are built-in internals:
/// (mask_index, bit_index)
const fn mask_indices(index: u32) -> (usize, u32)
*/