pub struct LlamaTokenAttrs(pub BitFlags<LlamaTokenAttr>);Expand description
A set of LlamaTokenAttrs
Tuple Fields§
§0: BitFlags<LlamaTokenAttr>Methods from Deref<Target = BitFlags<LlamaTokenAttr>>§
Sourcepub fn iter(self) -> Iter<T> ⓘ
pub fn iter(self) -> Iter<T> ⓘ
Iterate over the BitFlags.
let flags = make_bitflags!(MyFlag::{A | C});
flags.iter()
.for_each(|flag| println!("{:?}", flag));Sourcepub fn union_c(self, other: BitFlags<T, u8>) -> BitFlags<T, u8>
pub fn union_c(self, other: BitFlags<T, u8>) -> BitFlags<T, u8>
Bitwise OR — return value contains flag if either argument does.
Also available as a | b, but operator overloads are not usable
in const fns at the moment.
Sourcepub fn intersection_c(self, other: BitFlags<T, u8>) -> BitFlags<T, u8>
pub fn intersection_c(self, other: BitFlags<T, u8>) -> BitFlags<T, u8>
Bitwise AND — return value contains flag if both arguments do.
Also available as a & b, but operator overloads are not usable
in const fns at the moment.
Sourcepub fn not_c(self, const_token: ConstToken<T, u8>) -> BitFlags<T, u8>
pub fn not_c(self, const_token: ConstToken<T, u8>) -> BitFlags<T, u8>
Bitwise NOT — return value contains flag if argument doesn’t.
Also available as !a, but operator overloads are not usable
in const fns at the moment.
Moreover, due to const fn limitations, not_c needs a
ConstToken as an argument.
#[bitflags]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum MyFlag {
One = 1 << 0,
Two = 1 << 1,
Three = 1 << 2,
}
const FLAGS: BitFlags<MyFlag> = make_bitflags!(MyFlag::{One | Two});
const NEGATED: BitFlags<MyFlag> = FLAGS.not_c(BitFlags::CONST_TOKEN);
assert_eq!(NEGATED, MyFlag::Three);Sourcepub fn exactly_one(self) -> Option<T>
pub fn exactly_one(self) -> Option<T>
If exactly one flag is set, the flag is returned. Otherwise, returns None.
See also Itertools::exactly_one.
Sourcepub fn bits(self) -> <T as RawBitFlags>::Numeric
pub fn bits(self) -> <T as RawBitFlags>::Numeric
Returns the underlying bitwise value.
#[bitflags]
#[repr(u8)]
#[derive(Clone, Copy)]
enum Flags {
Foo = 1 << 0,
Bar = 1 << 1,
}
let both_flags = Flags::Foo | Flags::Bar;
assert_eq!(both_flags.bits(), 0b11);Sourcepub fn intersects<B>(self, other: B) -> bool
pub fn intersects<B>(self, other: B) -> bool
Returns true if at least one flag is shared.
Sourcepub fn set<B>(&mut self, other: B, cond: bool)
pub fn set<B>(&mut self, other: B, cond: bool)
Inserts if cond holds, else removes
#[bitflags]
#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(u8)]
enum MyFlag {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2,
}
let mut state = MyFlag::A | MyFlag::C;
state.set(MyFlag::A | MyFlag::B, false);
// Because the condition was false, both
// `A` and `B` are removed from the set
assert_eq!(state, MyFlag::C);