Search code examples
rustrust-cargo

How to cast rust bitflags entries into int


How to use bitflag entries as int. For eaxmple:

bitflags! {
    struct Flags: u8 {
        const NONE = 1;
        const SOME = 2;
    }
}

Now if I want to compare Flags::SOME == 2, how to cast the Flags::SOME to u8?


Solution

  • Just discovered it can be done using 'bits()':

    Flags::SOME.bits() == 2