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
/// Simple bitflags macro to avoid pulling in the bitflags crate
macro_rules! bitflags {
(
$(#[$outer:meta])*
$vis:vis struct $Name:ident: $T:ty {
$(
$(#[$inner:meta])*
const $Flag:ident = $value:expr;
)*
}
) => {
$(#[$outer])*
$vis struct $Name {
bits: $T,
}
impl $Name {
$(
$(#[$inner])*
pub const $Flag: Self = Self { bits: $value };
)*
pub const fn empty() -> Self {
Self { bits: 0 }
}
pub const fn bits(&self) -> $T {
self.bits
}
/// Wrap raw bits, retaining every bit (including bits with no
/// defined flag). Named to match its behavior; it does not mask
/// to known flags the way real `from_bits_truncate` would.
pub const fn from_bits_retain(bits: $T) -> Self {
Self { bits }
}
pub const fn contains(&self, other: Self) -> bool {
(self.bits & other.bits) == other.bits
}
}
impl std::ops::BitOr for $Name {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self { bits: self.bits | rhs.bits }
}
}
impl std::ops::BitOrAssign for $Name {
fn bitor_assign(&mut self, rhs: Self) {
self.bits |= rhs.bits;
}
}
};
}