pub trait Flags: Sized + 'static {
type Bits: Bits;
const FLAGS: &'static [Flag<Self>];
Show 22 methods
// Required methods
fn bits(&self) -> Self::Bits;
fn from_bits_retain(bits: Self::Bits) -> Self;
// Provided methods
fn empty() -> Self { ... }
fn all() -> Self { ... }
fn from_bits(bits: Self::Bits) -> Option<Self> { ... }
fn from_bits_truncate(bits: Self::Bits) -> Self { ... }
fn from_name(name: &str) -> Option<Self> { ... }
fn iter(&self) -> Iter<Self> ⓘ { ... }
fn iter_names(&self) -> IterNames<Self> ⓘ { ... }
fn is_empty(&self) -> bool { ... }
fn is_all(&self) -> bool { ... }
fn intersects(&self, other: Self) -> bool
where Self: Sized { ... }
fn contains(&self, other: Self) -> bool
where Self: Sized { ... }
fn insert(&mut self, other: Self)
where Self: Sized { ... }
fn remove(&mut self, other: Self)
where Self: Sized { ... }
fn toggle(&mut self, other: Self)
where Self: Sized { ... }
fn set(&mut self, other: Self, value: bool)
where Self: Sized { ... }
fn intersection(self, other: Self) -> Self { ... }
fn union(self, other: Self) -> Self { ... }
fn difference(self, other: Self) -> Self { ... }
fn symmetric_difference(self, other: Self) -> Self { ... }
fn complement(self) -> Self { ... }
}
Expand description
A set of flags.
This trait is automatically implemented for flags types defined using the bitflags!
macro.
It can also be implemented manually for custom flags types.
Required Associated Types§
Required Associated Constants§
Required Methods§
sourcefn from_bits_retain(bits: Self::Bits) -> Self
fn from_bits_retain(bits: Self::Bits) -> Self
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Provided Methods§
sourcefn from_bits(bits: Self::Bits) -> Option<Self>
fn from_bits(bits: Self::Bits) -> Option<Self>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
Note that each multi-bit flag is treated as a unit for this comparison.
sourcefn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
Note that each multi-bit flag is treated as a unit for this comparison.
sourcefn iter_names(&self) -> IterNames<Self> ⓘ
fn iter_names(&self) -> IterNames<Self> ⓘ
Iterate over the raw names and bits for enabled flag values.
sourcefn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere Self: Sized,
Returns true
if there are flags common to both self
and other
.
sourcefn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere Self: Sized,
Returns true
if all of the flags in other
are contained within self
.
sourcefn set(&mut self, other: Self, value: bool)where
Self: Sized,
fn set(&mut self, other: Self, value: bool)where Self: Sized,
Inserts or removes the specified flags depending on the passed value.
sourcefn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
Returns the intersection between the flags in self
and
other
.
Specifically, the returned set contains only the flags which are
present in both self
and other
.
sourcefn union(self, other: Self) -> Self
fn union(self, other: Self) -> Self
Returns the union of between the flags in self
and other
.
Specifically, the returned set contains all flags which are
present in either self
or other
, including any which are
present in both (see Self::symmetric_difference
if that
is undesirable).
sourcefn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
Returns the difference between the flags in self
and other
.
Specifically, the returned set contains all flags present in
self
, except for the ones present in other
.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other
(and this syntax is also supported).
sourcefn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference between the flags
in self
and other
.
Specifically, the returned set contains the flags present which
are present in self
or other
, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self
and other
.
sourcefn complement(self) -> Self
fn complement(self) -> Self
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self
, but which are allowed for this type.