pub trait BitFlagExt<T, U>: Sizedwhere
U: ?Sized,{
// Required methods
fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn try_from_bit(i: u8) -> Option<Self>
where T: PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn try_from_bits(bits: T) -> Option<Self>
where T: PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn try_from_bits_retain(bits: T) -> Option<Self>
where T: IntOpsExt;
fn is_valid(&self) -> bool
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
fn mask(&self) -> Option<T>
where T: IntOpsExt;
fn intersection(self, other: Self) -> BitFlags<T, U>
where T: Copy + BitAnd<T, Output = T> + IntOpsExt;
fn union(self, other: Self) -> BitFlags<T, U>
where T: Copy + BitOr<T, Output = T> + IntOpsExt;
fn difference(self, other: Self) -> BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt;
fn symmetric_difference(self, other: Self) -> BitFlags<T, U>
where T: Copy + BitXor<T, Output = T> + IntOpsExt;
fn complement(self) -> BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,
U: BitFlagsSpec<T>;
}Expand description
Extension trait providing generic, non-const equivalents of the
type-specific inherent methods on BitFlag.
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 try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that bit is
valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set, or the
single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on flags.bits().
Sourcefn try_from_bit(i: u8) -> Option<Self>
fn try_from_bit(i: u8) -> Option<Self>
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcefn try_from_bits(bits: T) -> Option<Self>
fn try_from_bits(bits: T) -> Option<Self>
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcefn try_from_bits_retain(bits: T) -> Option<Self>where
T: IntOpsExt,
fn try_from_bits_retain(bits: T) -> Option<Self>where
T: IntOpsExt,
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcefn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcefn mask(&self) -> Option<T>where
T: IntOpsExt,
fn mask(&self) -> Option<T>where
T: IntOpsExt,
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcefn intersection(self, other: Self) -> BitFlags<T, U>
fn intersection(self, other: Self) -> BitFlags<T, U>
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) -> BitFlags<T, U>
fn union(self, other: Self) -> BitFlags<T, U>
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) -> BitFlags<T, U>
fn difference(self, other: Self) -> BitFlags<T, U>
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) -> BitFlags<T, U>
fn symmetric_difference(self, other: Self) -> BitFlags<T, U>
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) -> BitFlags<T, U>
fn complement(self) -> BitFlags<T, U>
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".