assert_eq!(3,defined_flags::<MyFlags>()); ```
*/ pubtrait Flags: Sized + 'static { /// The set of defined flags. const FLAGS: &'static [Flag<Self>];
/// The underlying bits type. type Bits: Bits;
/// Get a flags value with all bits unset. fn empty() -> Self { Self::from_bits_retain(Self::Bits::EMPTY)
}
/// Get a flags value with all known bits set. fn all() -> Self { letmut truncated = Self::Bits::EMPTY;
for flag inSelf::FLAGS.iter() {
truncated = truncated | flag.value().bits();
}
Self::from_bits_retain(truncated)
}
/// This method will return `true` if any unknown bits are set. fn contains_unknown_bits(&self) -> bool { Self::all().bits() & self.bits() != self.bits()
}
/// Get the underlying bits value. /// /// The returned value is exactly the bits set in this flags value. fn bits(&self) -> Self::Bits;
/// Convert from a bits value. /// /// This method will return `None` if any unknown bits are set. fn from_bits(bits: Self::Bits) -> Option<Self> { let truncated = Self::from_bits_truncate(bits);
/// Convert from a bits value, unsetting any unknown bits. fn from_bits_truncate(bits: Self::Bits) -> Self { Self::from_bits_retain(bits & Self::all().bits())
}
/// Convert from a bits value exactly. fn from_bits_retain(bits: Self::Bits) -> Self;
/// Get a flags value with the bits of a flag with the given name set. /// /// This method will return `None` if `name` is empty or doesn't /// correspond to any named flag. fn from_name(name: &str) -> Option<Self> { // Don't parse empty names as empty flags if name.is_empty() { return None;
}
for flag inSelf::FLAGS { if flag.name() == name { return Some(Self::from_bits_retain(flag.value().bits()));
}
}
None
}
/// Yield a set of contained flags values. /// /// Each yielded flags value will correspond to a defined named flag. Any unknown bits /// will be yielded together as a final flags value. fn iter(&self) -> iter::Iter<Self> {
iter::Iter::new(self)
}
/// Yield a set of contained named flags values. /// /// This method is like [`Flags::iter`], except only yields bits in contained named flags. /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded. fn iter_names(&self) -> iter::IterNames<Self> {
iter::IterNames::new(self)
}
/// Whether all bits in this flags value are unset. fn is_empty(&self) -> bool { self.bits() == Self::Bits::EMPTY
}
/// Whether all known bits in this flags value are set. fn is_all(&self) -> bool { // NOTE: We check against `Self::all` here, not `Self::Bits::ALL` // because the set of all flags may not use all bits Self::all().bits() | self.bits() == self.bits()
}
/// Whether any set bits in a source flags value are also set in a target flags value. fn intersects(&self, other: Self) -> bool where Self: Sized,
{ self.bits() & other.bits() != Self::Bits::EMPTY
}
/// Whether all set bits in a source flags value are also set in a target flags value. fn contains(&self, other: Self) -> bool where Self: Sized,
{ self.bits() & other.bits() == other.bits()
}
/// Remove any unknown bits from the flags. fn truncate(&mutself) where Self: Sized,
{
*self = Self::from_bits_truncate(self.bits());
}
/// The bitwise or (`|`) of the bits in two flags values. fn insert(&mutself, other: Self) where Self: Sized,
{
*self = Self::from_bits_retain(self.bits()).union(other);
}
/// The intersection of a source flags value with the complement of a target flags value (`&!`).> /// /// This method is not equivalent to `self & !other` when `other` has unknown bits set. /// `remove` won't truncate `other`, but the `!` operator will. fn remove(&mutself, other: Self) where Self: Sized,
{
*self = Self::from_bits_retain(self.bits()).difference(other);
}
/// The bitwise exclusive-or (`^`) of the bits in two flags values. fn toggle(&mutself, other: Self) where Self: Sized,
{
*self = Self::from_bits_retain(self.bits()).symmetric_difference(other);
}
/// Call [`Flags::insert`] when `value` is `true` or [`Flags::remove`] when `value` is `false`. fn set(&mutself, other: Self, value: bool) where Self: Sized,
{ if value { self.insert(other);
} else { self.remove(other);
}
}
/// The bitwise and (`&`) of the bits in two flags values. #[must_use] fn intersection(self, other: Self) -> Self { Self::from_bits_retain(self.bits() & other.bits())
}
/// The bitwise or (`|`) of the bits in two flags values. #[must_use] fn union(self, other: Self) -> Self { Self::from_bits_retain(self.bits() | other.bits())
}
/// The intersection of a source flags value with the complement of a target flags value (`&!`).> /// /// This method is not equivalent to `self & !other` when `other` has unknown bits set. /// `difference` won't truncate `other`, but the `!` operator will. #[must_use] fn difference(self, other: Self) -> Self { Self::from_bits_retain(self.bits() & !other.bits())
}
/// The bitwise exclusive-or (`^`) of the bits in two flags values. #[must_use] fn symmetric_difference(self, other: Self) -> Self { Self::from_bits_retain(self.bits() ^ other.bits())
}
/// The bitwise negation (`!`) of the bits in a flags value, truncating the result. #[must_use] fn complement(self) -> Self { Self::from_bits_truncate(!self.bits())
}
}
// Not re-exported: prevent custom `Bits` impls being used in the `bitflags!` macro, // or they may fail to compile based on crate features pubtrait Primitive {}
/// A trait for referencing the `bitflags`-owned internal type /// without exposing it publicly. pubtrait PublicFlags { /// The type of the underlying storage. type Primitive: Primitive;
/// The type of the internal field on the generated flags type. type Internal;
}
#[doc(hidden)] #[deprecated(note = "use the `Flags` trait instead")] pubtrait BitFlags: ImplementedByBitFlagsMacro + Flags { /// An iterator over enabled flags in an instance of the type. type Iter: Iterator<Item = Self>;
/// An iterator over the raw names and bits for enabled flags in an instance of the type. type IterNames: Iterator<Item = (&'static str, Self)>;
}
#[allow(deprecated)] impl<B: Flags> BitFlags for B { type Iter = iter::Iter<Self>; type IterNames = iter::IterNames<Self>;
}
impl<B: Flags> ImplementedByBitFlagsMacro for B {}
/// A marker trait that signals that an implementation of `BitFlags` came from the `bitflags!` macro. /// /// There's nothing stopping an end-user from implementing this trait, but we don't guarantee their /// manual implementations won't break between non-breaking releases. #[doc(hidden)] pubtrait ImplementedByBitFlagsMacro {}
pub(crate) mod __private { pubusesuper::{ImplementedByBitFlagsMacro, PublicFlags};
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.