Skip to main content

BitFlagsExt

Trait BitFlagsExt 

Source
pub trait BitFlagsExt<T, U>: Sized
where 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§

Source

fn from_flag(bit_flag: BitFlag<T, U>) -> Self
where 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.

Source

fn from_bit_retain(bit: u8) -> Self
where 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.

Source

fn from_bit_truncate(bit: u8) -> Self
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

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.

Source

fn try_from_bit(bit: u8) -> Option<Self>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

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.

Source

fn try_from_bits(bits: T) -> Option<Self>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

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.

Source

fn from_bits_truncate(bits: T) -> Self
where 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.

Source

fn is_empty(&self) -> bool
where T: Copy + PartialEq + IntOpsExt,

Returns true if no bits are set.

This checks the raw stored bits. A value containing only invalid bits is not empty.

Source

fn is_valid(&self) -> bool
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

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.

Source

fn intersects(&self, other: Self) -> bool
where T: Copy + PartialEq + BitAnd<T, Output = T> + IntOpsExt,

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.

Source

fn contains(&self, other: Self) -> bool
where T: Copy + PartialEq + BitAnd<T, Output = T>,

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.

Source

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.

Source

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.

Source

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.

Source

fn remove(&mut self, other: Self)
where T: Copy + Not<Output = T> + BitAndAssign<T>,

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.

Source

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.

Source

fn set(&mut self, other: Self, value: bool)
where T: Copy + Not<Output = T> + BitAndAssign<T> + BitOrAssign<T>,

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.

Source

fn intersection(self, other: Self) -> Self
where T: Copy + BitAnd<T, Output = T>,

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.

Source

fn union(self, other: Self) -> Self
where T: Copy + BitOr<T, Output = T>,

Returns the union of self and other.

This is a raw-bit operation. Invalid bits in either operand are preserved.

Source

fn difference(self, other: Self) -> Self
where T: Copy + Not<Output = T> + BitAnd<T, Output = T>,

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.

Source

fn symmetric_difference(self, other: Self) -> Self
where T: Copy + BitXor<T, Output = T>,

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.

Source

fn complement(self) -> Self
where T: Copy + Not<Output = T> + BitAnd<T, Output = T>, U: BitFlagsSpec<T>,

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".

Implementors§

Source§

impl<T, U> BitFlagsExt<T, U> for BitFlags<T, U>
where U: ?Sized,