Trait enumflags2::BitFlag
source · pub trait BitFlag: Copy + Clone + 'static + RawBitFlags {
fn empty() -> BitFlags<Self> { ... }
fn all() -> BitFlags<Self> { ... }
}
Expand description
A trait automatically implemented by #[bitflags]
to make the enum
a valid type parameter for BitFlags<T>
.
Provided Methods§
sourcefn empty() -> BitFlags<Self>
fn empty() -> BitFlags<Self>
Create a BitFlags
with no flags set (in other words, with a value of 0).
This is a convenience reexport of BitFlags::empty
. It can be called with
MyFlag::empty()
, thus bypassing the need for type hints in some situations.
#[bitflags]
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq)]
enum MyFlag {
One = 1 << 0,
Two = 1 << 1,
Three = 1 << 2,
}
use enumflags2::BitFlag;
let empty = MyFlag::empty();
assert!(empty.is_empty());
assert_eq!(empty.contains(MyFlag::One), false);
assert_eq!(empty.contains(MyFlag::Two), false);
assert_eq!(empty.contains(MyFlag::Three), false);
sourcefn all() -> BitFlags<Self>
fn all() -> BitFlags<Self>
Create a BitFlags
with all flags set.
This is a convenience reexport of BitFlags::all
. It can be called with
MyFlag::all()
, thus bypassing the need for type hints in some situations.
#[bitflags]
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq)]
enum MyFlag {
One = 1 << 0,
Two = 1 << 1,
Three = 1 << 2,
}
use enumflags2::BitFlag;
let empty = MyFlag::all();
assert!(empty.is_all());
assert_eq!(empty.contains(MyFlag::One), true);
assert_eq!(empty.contains(MyFlag::Two), true);
assert_eq!(empty.contains(MyFlag::Three), true);