pub trait BitFlagsExt<T, U>: Sizedwhere
U: ?Sized,{
Show 21 methods
// Required methods
fn from_flag(bit_flag: BitFlag<T, U>) -> Self
where T: IntOpsExt;
fn from_bit_retain(bit: u8) -> Self
where T: IntOpsExt;
fn from_bit_truncate(bit: u8) -> Self
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn try_from_bit(bit: u8) -> Option<Self>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn try_from_bits(bits: T) -> Option<Self>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn from_bits_truncate(bits: T) -> Self
where T: BitAnd<T, Output = T>,
U: BitFlagsSpec<T>;
fn is_empty(&self) -> bool
where T: Copy + PartialEq + IntOpsExt;
fn is_valid(&self) -> bool
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn intersects(&self, other: Self) -> bool
where T: Copy + PartialEq + BitAnd<T, Output = T> + IntOpsExt;
fn contains(&self, other: Self) -> bool
where T: Copy + PartialEq + BitAnd<T, Output = T>;
fn clear(&mut self)
where T: IntOpsExt;
fn truncate(&mut self)
where T: BitAndAssign<T>,
U: BitFlagsSpec<T>;
fn insert(&mut self, other: Self)
where T: Copy + BitOrAssign<T>;
fn remove(&mut self, other: Self)
where T: Copy + Not<Output = T> + BitAndAssign<T>;
fn toggle(&mut self, other: Self)
where T: Copy + BitXorAssign<T>;
fn set(&mut self, other: Self, value: bool)
where T: Copy + Not<Output = T> + BitAndAssign<T> + BitOrAssign<T>;
fn intersection(self, other: Self) -> Self
where T: Copy + BitAnd<T, Output = T>;
fn union(self, other: Self) -> Self
where T: Copy + BitOr<T, Output = T>;
fn difference(self, other: Self) -> Self
where T: Copy + Not<Output = T> + BitAnd<T, Output = T>;
fn symmetric_difference(self, other: Self) -> Self
where T: Copy + BitXor<T, Output = T>;
fn complement(self) -> Self
where T: Copy + Not<Output = T> + BitAnd<T, Output = T>,
U: BitFlagsSpec<T>;
}Expand description
Extension trait providing generic, non-const equivalents of the
type-specific inherent methods on BitFlags.
The inherent methods are implemented for each concrete integer type so they
can be const.
This trait exposes the same operations for generic T.
Required Methods§
Sourcefn from_flag(bit_flag: BitFlag<T, U>) -> Selfwhere
T: IntOpsExt,
fn from_flag(bit_flag: BitFlag<T, U>) -> Selfwhere
T: IntOpsExt,
Creates a flag set from a single BitFlag.
The bit index is not validated against
BitFlagsSpec::VALID_BITS_MASK.
The resulting value may contain an invalid bit.
If the flag’s index is outside the width of T, the result is
BitFlags::empty.
Sourcefn from_bit_retain(bit: u8) -> Selfwhere
T: IntOpsExt,
fn from_bit_retain(bit: u8) -> Selfwhere
T: IntOpsExt,
Creates a flag set with only the bit at index bit set.
The bit index is not validated against
BitFlagsSpec::VALID_BITS_MASK.
The resulting value may contain an invalid bit. Use
BitFlags::try_from_bit or BitFlags::from_bits_truncate when
validation or truncation is required.
If bit is outside the width of T, the result is
BitFlags::empty.
Sourcefn from_bit_truncate(bit: u8) -> Self
fn from_bit_truncate(bit: u8) -> Self
Creates a flag set with only the bit at index bit set, clearing the
bit if it is not valid for the tag.
This is the bit-index counterpart to BitFlags::from_bits_truncate.
If bit is outside the width of T, or if the corresponding bit is
not present in BitFlagsSpec::VALID_BITS_MASK, the result is
BitFlags::empty.
The result always contains either exactly one bit or no bits.
Use BitFlags::try_from_bit when the caller needs to distinguish a
valid index from an invalid one.
Sourcefn try_from_bit(bit: u8) -> Option<Self>
fn try_from_bit(bit: u8) -> Option<Self>
Creates a flag set from bit index bit if that bit is valid.
Returns None if bit is outside the width of T or if the resulting
bit is not present in BitFlagsSpec::VALID_BITS_MASK.
Sourcefn try_from_bits(bits: T) -> Option<Self>
fn try_from_bits(bits: T) -> Option<Self>
Creates a flag set from raw bits if all set bits are valid.
Returns None if bits contains any bit not present in
BitFlagsSpec::VALID_BITS_MASK.
Use BitFlags::from_bits_retain to keep invalid bits, or
BitFlags::from_bits_truncate to clear them.
Sourcefn from_bits_truncate(bits: T) -> Selfwhere
T: BitAnd<T, Output = T>,
U: BitFlagsSpec<T>,
fn from_bits_truncate(bits: T) -> Selfwhere
T: BitAnd<T, Output = T>,
U: BitFlagsSpec<T>,
Creates a flag set from raw bits, clearing any bits not present in
BitFlagsSpec::VALID_BITS_MASK.
This always succeeds and never stores invalid bits.
Sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns true if no bits are set.
This checks the raw stored bits. A value containing only invalid bits is not empty.
Sourcefn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Returns true if all set bits in self are valid for this tag.
A BitFlags value can contain bits not present in
BitFlagsSpec::VALID_BITS_MASK after construction with
BitFlags::from_bits_retain or after raw-bit operations such as
BitFlags::insert, BitFlags::toggle, and BitFlags::union.
This method returns false for such values.
Use BitFlags::truncate or BitFlags::from_bits_truncate to
restrict a value to its valid bits.
Sourcefn intersects(&self, other: Self) -> bool
fn intersects(&self, other: Self) -> bool
Returns true if self and other have at least one set bit in
common.
This compares raw bits. Invalid bits participate in the comparison if they are present.
Sourcefn contains(&self, other: Self) -> bool
fn contains(&self, other: Self) -> bool
Returns true if all bits set in other are also set in self.
This compares raw bits. Invalid bits participate in the comparison if they are present.
Sourcefn clear(&mut self)where
T: IntOpsExt,
fn clear(&mut self)where
T: IntOpsExt,
Removes all bits from self, including any invalid bits.
This is equivalent to assigning BitFlags::empty to self.
Sourcefn truncate(&mut self)where
T: BitAndAssign<T>,
U: BitFlagsSpec<T>,
fn truncate(&mut self)where
T: BitAndAssign<T>,
U: BitFlagsSpec<T>,
Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.
This leaves self unchanged if it already contains only valid bits.
Sourcefn insert(&mut self, other: Self)where
T: Copy + BitOrAssign<T>,
fn insert(&mut self, other: Self)where
T: Copy + BitOrAssign<T>,
Inserts all bits from other.
This is a raw-bit operation.
It does not validate or clear invalid bits.
Inserting other can introduce invalid bits into self.
Sourcefn remove(&mut self, other: Self)
fn remove(&mut self, other: Self)
Removes all bits from other.
This is a raw-bit operation. It cannot introduce new bits, but it does not clear any other invalid bits that may already be present.
Sourcefn toggle(&mut self, other: Self)where
T: Copy + BitXorAssign<T>,
fn toggle(&mut self, other: Self)where
T: Copy + BitXorAssign<T>,
Toggles all bits from other.
This is a raw-bit operation.
It does not validate or clear invalid bits.
Toggling other can introduce invalid bits into self.
Sourcefn set(&mut self, other: Self, value: bool)
fn set(&mut self, other: Self, value: bool)
Inserts other if value is true, or removes other if
value is false.
This is a raw-bit operation and follows the same invalid-bit
behavior as BitFlags::insert and BitFlags::remove.
Sourcefn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcefn union(self, other: Self) -> Self
fn union(self, other: Self) -> Self
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcefn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcefn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcefn complement(self) -> Self
fn complement(self) -> Self
Returns the complement of self.
All valid bits not set in self become set, and all invalid
bits become unset.
The result always contains only valid bits.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".