pub trait BitFlag:
Copy
+ Into<u8>
+ 'static {
type Mask: PrimInt;
const FLAGS: &'static [Flag<Self>];
const MAX_VALUE: u8;
// Provided methods
fn as_u8(self) -> u8 { ... }
fn as_usize(self) -> usize { ... }
fn mask(self) -> Self::Mask { ... }
}Expand description
A trait for types that represent individual bit flag positions.
Provides conversions between element values and their bitmask representations, plus a static list of all defined flags.
Use the [bitflag!] macro to auto-derive this trait:
bitflagset::bitflag! {
#[derive(Debug)]
#[repr(u8)]
enum Color {
Red = 0,
Green = 1,
Blue = 2,
}
}
use bitflagset::BitFlag;
assert_eq!(Color::FLAGS.len(), 3);
assert_eq!(Color::FLAGS[0].name(), "Red");
assert_eq!(Color::Red.mask(), 1u8);
assert_eq!(Color::Green.mask(), 2u8);Required Associated Constants§
Required Associated Types§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.