Skip to main content

BitFlagExt

Trait BitFlagExt 

Source
pub trait BitFlagExt<T, U>: Sized
where U: ?Sized,
{ // Required methods fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self> where T: 'static + Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>; fn try_from_bit(i: u8) -> Option<Self> where T: 'static + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>; fn try_from_bits(bits: T) -> Option<Self> where T: 'static + 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: 'static + Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>; fn mask(&self) -> Option<T> where T: IntOpsExt; fn mask_or_default(&self) -> T where T: Default + 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: 'static + 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§

Source

fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
where T: 'static + Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

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().

Source

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

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.

Source

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

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.

Source

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.

Source

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

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.

Source

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.

Source

fn mask_or_default(&self) -> T
where T: Default + IntOpsExt,

Returns the single-bit mask for this flag, or 0 if the bit index is outside the width of $ty.

This is the const-friendly equivalent of self.mask().unwrap_or(0).

Source

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

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) -> BitFlags<T, U>
where T: Copy + BitOr<T, Output = T> + IntOpsExt,

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) -> BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt,

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) -> BitFlags<T, U>
where T: Copy + BitXor<T, Output = T> + IntOpsExt,

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) -> BitFlags<T, U>
where T: 'static + Copy + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, 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> BitFlagExt<T, U> for BitFlag<T, U>
where U: ?Sized,