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
pub trait BitFlags {
    type Item;

    fn contains(&self, value: Self::Item) -> bool;
}

macro_rules! bit_flags {
    ($type:ident) => {
        impl BitFlags for $type {
            type Item = $type;

            /// Checks if the specified flags (bytes) are present.
            fn contains(&self, value: $type) -> bool {
                (self & value) != 0
            }
        }
    };
}

bit_flags!(i8);
bit_flags!(u8);
bit_flags!(i16);
bit_flags!(u16);
bit_flags!(i32);
bit_flags!(u32);
bit_flags!(i64);
bit_flags!(u64);
bit_flags!(isize);
bit_flags!(usize);