Skip to main content

BitFlags

Struct BitFlags 

Source
pub struct BitFlags<T, U>(/* private fields */)
where
    U: ?Sized;
Expand description

A type-safe set of flags stored in an integer T.

The second type parameter U is a tag type that distinguishes flag sets that share the same storage type. When U implements BitFlagsSpec, it defines which bits are valid.

BitFlags is #[repr(transparent)] over T, so it has the same layout as T.

§Invalid bits

A BitFlags value is not guaranteed to contain only valid bits. BitFlags::from_bits_retain can create a value with any bit pattern of T, and raw-bit operations such as BitFlags::insert, BitFlags::toggle, BitFlags::union, and bitwise operators preserve invalid bits. Use BitFlags::truncate, BitFlags::try_from_bits, or BitFlags::from_bits_truncate when a value must be restricted to BitFlagsSpec::VALID_BITS_MASK.

BitFlags::bits returns the raw stored bits, including any invalid bits that are present.

§Examples

use bitflags_lite::{BitFlags, BitFlagsSpec, NameMatcher};

struct PermissionsTag;

impl BitFlagsSpec<u32> for PermissionsTag {
    const VALID_BITS_MASK: u32 = (1 << 3) - 1;
    const FLAG_NAMES: &[&[&str]] = &[&["read"], &["write"], &["exec", "execute"]];
    const DEFAULT_NAME_MATCHER: NameMatcher = NameMatcher::Exact;
}

type Permissions = BitFlags<u32, PermissionsTag>;

const READ: Permissions = Permissions::try_from_bits(1 << 0).unwrap();
const WRITE: Permissions = Permissions::try_from_bits(1 << 1).unwrap();
const EXEC: Permissions = Permissions::try_from_bits(1 << 2).unwrap();

let rw = READ | WRITE;
assert!(rw.contains(READ));
assert!(rw.contains(WRITE));
assert!(!rw.contains(EXEC));

§Method summary

Implementations§

Source§

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

Source

pub const fn empty() -> Self
where T: IntOpsExt,

Creates a flag set with no bits set (zero bits).

This is equivalent to from_bits_retain(0).

Source

pub const fn all_valid() -> Self
where U: BitFlagsSpec<T>,

Creates a flag set containing all valid bits for this tag.

This returns exactly BitFlagsSpec::VALID_BITS_MASK. Invalid bits are never set.

The method is named all_valid rather than all because a BitFlags value can contain invalid bits after BitFlags::from_bits_retain. In that case, “all” would be ambiguous: all bits of the storage type, all bits currently set, or all valid bits?

all_valid makes the meaning explicit.

Source

pub const fn from_bits_retain(bits: T) -> Self

Creates a flag set from raw bits without validation.

The resulting value may contain bits not present in BitFlagsSpec::VALID_BITS_MASK. Such invalid bits are preserved by this constructor and by raw-bit operations unless an operation clears them, such as BitFlags::truncate, BitFlags::complement, BitFlags::from_bits_truncate, or Not.

Source

pub const fn bits(&self) -> T
where T: Copy,

Returns the raw bits stored in this flag set.

The returned value may contain invalid bits if this value was created with BitFlags::from_bits_retain and has not since been passed through an operation that clears invalid bits, such as BitFlags::truncate or BitFlags::complement.

Source

pub const fn bits_mut(&mut self) -> &mut T

Returns a mutable reference to the raw bits stored in this flag set.

Mutating the returned value can introduce invalid bits. Use BitFlags::truncate afterwards if the value must contain only valid bits.

Source

pub fn into_bits(self) -> T

Consumes this flag set and returns the raw bits.

This is the consuming counterpart to BitFlags::bits. Like BitFlags::bits, the returned value may contain bits not present in BitFlagsSpec::VALID_BITS_MASK.

This method does not require T: Copy, so it is available for storage types that are not Copy.

Source

pub const fn iter(self) -> BitFlagsIter<T, U> ⓘ
where T: Copy + Not<Output = T> + BitAndAssign<T> + IntOpsExt,

Returns an iterator over the individual set bits in this flag set.

The iterator yields BitFlag values from the least significant bit to the most significant bit. It includes invalid bits if they are present.

Source

pub fn try_from_str( input: &str, separator: &'static str, name_matcher: NameMatcher, ) -> Result<Self, BitFlagsParseError>
where T: BitOrAssign<T> + IntOpsExt, U: BitFlagsSpec<T>,

Parses a flag set from a string.

The input may be empty, which returns BitFlags::empty. Otherwise it is split on given separator, and each part is trimmed and matched against the names in BitFlagsSpec::FLAG_NAMES. Match behavior is specified by name_matcher. A part may also be a hexadecimal flag with a 0x prefix.

This method does not validate or truncate the parsed bits against BitFlagsSpec::VALID_BITS_MASK. The returned value may contain invalid bits.

Note that if separator is an empty string, the method would split into individual characters, which is almost certainly not intended.

§Errors

Returns BitFlagsParseError if input is not a separator-separated list of named flags or hexadecimal flags.

Source§

impl<U> BitFlags<u8, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<u8, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<u8>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<u8>,

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

pub const fn try_from_bits(bits: u8) -> Option<Self>
where U: BitFlagsSpec<u8>,

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

pub const fn from_bits_truncate(bits: u8) -> Self
where U: BitFlagsSpec<u8>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<u8>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<u8>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<u8>,

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.

Source§

impl<U> BitFlags<u16, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<u16, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<u16>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<u16>,

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

pub const fn try_from_bits(bits: u16) -> Option<Self>
where U: BitFlagsSpec<u16>,

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

pub const fn from_bits_truncate(bits: u16) -> Self
where U: BitFlagsSpec<u16>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<u16>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<u16>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<u16>,

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.

Source§

impl<U> BitFlags<u32, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<u32, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<u32>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<u32>,

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

pub const fn try_from_bits(bits: u32) -> Option<Self>
where U: BitFlagsSpec<u32>,

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

pub const fn from_bits_truncate(bits: u32) -> Self
where U: BitFlagsSpec<u32>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<u32>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<u32>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<u32>,

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.

Source§

impl<U> BitFlags<u64, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<u64, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<u64>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<u64>,

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

pub const fn try_from_bits(bits: u64) -> Option<Self>
where U: BitFlagsSpec<u64>,

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

pub const fn from_bits_truncate(bits: u64) -> Self
where U: BitFlagsSpec<u64>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<u64>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<u64>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<u64>,

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.

Source§

impl<U> BitFlags<u128, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<u128, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<u128>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<u128>,

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

pub const fn try_from_bits(bits: u128) -> Option<Self>
where U: BitFlagsSpec<u128>,

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

pub const fn from_bits_truncate(bits: u128) -> Self
where U: BitFlagsSpec<u128>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<u128>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<u128>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<u128>,

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.

Source§

impl<U> BitFlags<usize, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<usize, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<usize>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<usize>,

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

pub const fn try_from_bits(bits: usize) -> Option<Self>
where U: BitFlagsSpec<usize>,

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

pub const fn from_bits_truncate(bits: usize) -> Self
where U: BitFlagsSpec<usize>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<usize>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<usize>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<usize>,

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.

Source§

impl<U> BitFlags<i8, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<i8, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<i8>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<i8>,

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

pub const fn try_from_bits(bits: i8) -> Option<Self>
where U: BitFlagsSpec<i8>,

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

pub const fn from_bits_truncate(bits: i8) -> Self
where U: BitFlagsSpec<i8>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<i8>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<i8>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<i8>,

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.

Source§

impl<U> BitFlags<i16, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<i16, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<i16>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<i16>,

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

pub const fn try_from_bits(bits: i16) -> Option<Self>
where U: BitFlagsSpec<i16>,

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

pub const fn from_bits_truncate(bits: i16) -> Self
where U: BitFlagsSpec<i16>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<i16>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<i16>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<i16>,

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.

Source§

impl<U> BitFlags<i32, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<i32, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<i32>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<i32>,

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

pub const fn try_from_bits(bits: i32) -> Option<Self>
where U: BitFlagsSpec<i32>,

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

pub const fn from_bits_truncate(bits: i32) -> Self
where U: BitFlagsSpec<i32>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<i32>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<i32>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<i32>,

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.

Source§

impl<U> BitFlags<i64, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<i64, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<i64>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<i64>,

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

pub const fn try_from_bits(bits: i64) -> Option<Self>
where U: BitFlagsSpec<i64>,

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

pub const fn from_bits_truncate(bits: i64) -> Self
where U: BitFlagsSpec<i64>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<i64>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<i64>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<i64>,

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.

Source§

impl<U> BitFlags<i128, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<i128, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<i128>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<i128>,

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

pub const fn try_from_bits(bits: i128) -> Option<Self>
where U: BitFlagsSpec<i128>,

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

pub const fn from_bits_truncate(bits: i128) -> Self
where U: BitFlagsSpec<i128>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<i128>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<i128>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<i128>,

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.

Source§

impl<U> BitFlags<isize, U>
where U: ?Sized,

Source

pub const fn from_flag(flag: BitFlag<isize, U>) -> Self

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

pub const fn from_bit_retain(bit: u8) -> Self

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

pub const fn from_bit_truncate(bit: u8) -> Self
where U: BitFlagsSpec<isize>,

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

pub const fn try_from_bit(bit: u8) -> Option<Self>
where U: BitFlagsSpec<isize>,

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

pub const fn try_from_bits(bits: isize) -> Option<Self>
where U: BitFlagsSpec<isize>,

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

pub const fn from_bits_truncate(bits: isize) -> Self
where U: BitFlagsSpec<isize>,

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

pub const 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.

Source

pub const fn is_valid(&self) -> bool
where U: BitFlagsSpec<isize>,

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

pub const 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.

Source

pub const 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.

Source

pub const fn insert(&mut self, other: Self)

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

pub const fn clear(&mut self)

Removes all bits from self, including any invalid bits.

This is equivalent to assigning BitFlags::empty to self.

Source

pub const fn truncate(&mut self)
where U: BitFlagsSpec<isize>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK.

This leaves self unchanged if it already contains only valid bits.

Source

pub const 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.

Source

pub const fn toggle(&mut self, other: Self)

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

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const 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.

Source

pub const fn complement(self) -> Self
where U: BitFlagsSpec<isize>,

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.

Trait Implementations§

Source§

impl<'a, T, U> Arbitrary<'a> for BitFlags<T, U>
where T: Arbitrary<'a>, U: ?Sized,

Available on crate feature arbitrary only.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

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

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> BitAnd for BitFlags<T, U>
where T: BitAnd<T, Output = T>, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, U> BitAnd<BitFlag<T, U>> for BitFlags<T, U>
where T: BitAnd<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: BitFlag<T, U>) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, U> BitAnd<BitFlags<T, U>> for BitFlag<T, U>
where T: BitAnd<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: BitFlags<T, U>) -> Self::Output

Performs the & operation. Read more
Source§

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

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<T, U> BitAndAssign<BitFlag<T, U>> for BitFlags<T, U>
where T: BitAndAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn bitand_assign(&mut self, rhs: BitFlag<T, U>)

Performs the &= operation. Read more
Source§

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

Source§

fn from_flag(bit_flag: BitFlag<T, U>) -> Self
where T: IntOpsExt,

Creates a flag set from a single BitFlag. Read more
Source§

fn from_bit_retain(bit: u8) -> Self
where T: IntOpsExt,

Creates a flag set with only the bit at index bit set. Read more
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. Read more
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. Read more
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. Read more
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. Read more
Source§

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

Returns true if no bits are set. Read more
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. Read more
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. Read more
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. Read more
Source§

fn clear(&mut self)
where T: IntOpsExt,

Removes all bits from self, including any invalid bits. Read more
Source§

fn truncate(&mut self)
where T: BitAndAssign<T>, U: BitFlagsSpec<T>,

Clears all bits not present in BitFlagsSpec::VALID_BITS_MASK. Read more
Source§

fn insert(&mut self, other: Self)
where T: Copy + BitOrAssign<T>,

Inserts all bits from other. Read more
Source§

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

Removes all bits from other. Read more
Source§

fn toggle(&mut self, other: Self)
where T: Copy + BitXorAssign<T>,

Toggles all bits from other. Read more
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. Read more
Source§

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

Returns the intersection of self and other. Read more
Source§

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

Returns the union of self and other. Read more
Source§

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

Returns the difference of self and other. Read more
Source§

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

Returns the symmetric difference of self and other. Read more
Source§

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

Returns the complement of self. Read more
Source§

impl<T, U> BitOr for BitFlags<T, U>
where T: BitOr<T, Output = T>, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, U> BitOr<BitFlag<T, U>> for BitFlags<T, U>
where T: BitOr<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: BitFlag<T, U>) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, U> BitOr<BitFlags<T, U>> for BitFlag<T, U>
where T: BitOr<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: BitFlags<T, U>) -> Self::Output

Performs the | operation. Read more
Source§

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

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<T, U> BitOrAssign<BitFlag<T, U>> for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn bitor_assign(&mut self, rhs: BitFlag<T, U>)

Performs the |= operation. Read more
Source§

impl<T, U> BitXor for BitFlags<T, U>
where T: BitXor<T, Output = T>, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T, U> BitXor<BitFlag<T, U>> for BitFlags<T, U>
where T: BitXor<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: BitFlag<T, U>) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T, U> BitXor<BitFlags<T, U>> for BitFlag<T, U>
where T: BitXor<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: BitFlags<T, U>) -> Self::Output

Performs the ^ operation. Read more
Source§

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

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<T, U> BitXorAssign<BitFlag<T, U>> for BitFlags<T, U>
where T: BitXorAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn bitxor_assign(&mut self, rhs: BitFlag<T, U>)

Performs the ^= operation. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T, U> Deserialize<'de> for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized + BitFlagsSpec<T>,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, U> Display for BitFlags<T, U>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + Shl<usize, Output = T> + LowerHex + IntOpsExt, U: ?Sized + BitFlagsSpec<T>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

impl<T, U> Extend<BitFlag<T, U>> for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = BitFlag<T, U>>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

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

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = Self>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, U> From<BitFlag<T, U>> for BitFlags<T, U>
where T: IntOpsExt, U: ?Sized,

Source§

fn from(flag: BitFlag<T, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<i8, U>> for i8
where U: ?Sized,

Source§

fn from(flags: BitFlags<i8, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<i16, U>> for i16
where U: ?Sized,

Source§

fn from(flags: BitFlags<i16, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<i32, U>> for i32
where U: ?Sized,

Source§

fn from(flags: BitFlags<i32, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<i64, U>> for i64
where U: ?Sized,

Source§

fn from(flags: BitFlags<i64, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<i128, U>> for i128
where U: ?Sized,

Source§

fn from(flags: BitFlags<i128, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<isize, U>> for isize
where U: ?Sized,

Source§

fn from(flags: BitFlags<isize, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<u8, U>> for u8
where U: ?Sized,

Source§

fn from(flags: BitFlags<u8, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<u16, U>> for u16
where U: ?Sized,

Source§

fn from(flags: BitFlags<u16, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<u32, U>> for u32
where U: ?Sized,

Source§

fn from(flags: BitFlags<u32, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<u64, U>> for u64
where U: ?Sized,

Source§

fn from(flags: BitFlags<u64, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<u128, U>> for u128
where U: ?Sized,

Source§

fn from(flags: BitFlags<u128, U>) -> Self

Converts to this type from the input type.
Source§

impl<U> From<BitFlags<usize, U>> for usize
where U: ?Sized,

Source§

fn from(flags: BitFlags<usize, U>) -> Self

Converts to this type from the input type.
Source§

impl<T, U> FromIterator<BitFlag<T, U>> for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = BitFlag<T, U>>,

Creates a value from an iterator. Read more
Source§

impl<T, U> FromIterator<BitFlags<T, U>> for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = Self>,

Creates a value from an iterator. Read more
Source§

impl<T, U> FromStr for BitFlags<T, U>
where T: BitOrAssign<T> + IntOpsExt, U: ?Sized + BitFlagsSpec<T>,

Source§

type Err = BitFlagsParseError

The associated error which can be returned from parsing.
Source§

fn from_str(input: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, U> IntoIterator for BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAndAssign<T> + IntOpsExt, U: ?Sized,

Source§

type IntoIter = BitFlagsIter<T, U>

Which kind of iterator are we turning this into?
Source§

type Item = BitFlag<T, U>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, U> IntoIterator for &BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAndAssign<T> + IntOpsExt, U: ?Sized,

Source§

type IntoIter = BitFlagsIter<T, U>

Which kind of iterator are we turning this into?
Source§

type Item = BitFlag<T, U>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, U> IntoIterator for &mut BitFlags<T, U>
where T: Copy + Not<Output = T> + BitAndAssign<T> + IntOpsExt, U: ?Sized,

Source§

type IntoIter = BitFlagsIter<T, U>

Which kind of iterator are we turning this into?
Source§

type Item = BitFlag<T, U>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> Not for BitFlags<T, U>
where T: Not<Output = T> + BitAnd<T, Output = T>, U: ?Sized + BitFlagsSpec<T>,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

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

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T, U> PartialEq<BitFlag<T, U>> for BitFlags<T, U>
where T: Copy + PartialEq + IntOpsExt, U: ?Sized,

Source§

fn eq(&self, other: &BitFlag<T, U>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T, U> PartialEq<BitFlags<T, U>> for BitFlag<T, U>
where T: Copy + PartialEq + IntOpsExt, U: ?Sized,

Source§

fn eq(&self, other: &BitFlags<T, U>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, U> PartialOrd<BitFlag<T, U>> for BitFlags<T, U>
where T: Copy + PartialOrd + IntOpsExt, U: ?Sized,

Source§

fn partial_cmp(&self, other: &BitFlag<T, U>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, U> PartialOrd<BitFlags<T, U>> for BitFlag<T, U>
where T: Copy + PartialOrd + IntOpsExt, U: ?Sized,

Source§

fn partial_cmp(&self, other: &BitFlags<T, U>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, U> Pod for BitFlags<T, U>
where T: Pod, U: 'static + ?Sized,

Available on crate feature bytemuck only.
Source§

impl<T, U> Serialize for BitFlags<T, U>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + Shl<usize, Output = T> + LowerHex + IntOpsExt, U: ?Sized + BitFlagsSpec<T>,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, U> Sub for BitFlags<T, U>
where T: Not<Output = T> + BitAnd<T, Output = T>, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U> Sub<BitFlag<T, U>> for BitFlags<T, U>
where T: Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BitFlag<T, U>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U> Sub<BitFlags<T, U>> for BitFlag<T, U>
where T: Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: ?Sized,

Source§

type Output = BitFlags<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BitFlags<T, U>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U> SubAssign for BitFlags<T, U>
where T: Not<Output = T> + BitAndAssign<T>, U: ?Sized,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<T, U> SubAssign<BitFlag<T, U>> for BitFlags<T, U>
where T: Not<Output = T> + BitAndAssign<T> + IntOpsExt, U: ?Sized,

Source§

fn sub_assign(&mut self, rhs: BitFlag<T, U>)

Performs the -= operation. Read more
Source§

impl<T, U> TryFrom<BitFlags<T, U>> for BitFlag<T, U>
where T: Copy + PartialEq + Not<Output = T> + BitAnd<T, Output = T> + IntOpsExt, U: BitFlagsSpec<T>,

Converts a flag set into a single-bit flag.

This fails unless flags contains exactly one set bit and that bit is valid for the tag. See BitFlag::try_from_flags.

Source§

type Error = BitFlagFromFlagsError

The type returned in the event of a conversion error.
Source§

fn try_from(flags: BitFlags<T, U>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Available on crate feature bytemuck only.
Source§

fn zeroed() -> Self

Auto Trait Implementations§

§

impl<T, U> Freeze for BitFlags<T, U>
where T: Freeze, PhantomData<fn() -> *const U>: Freeze, U: ?Sized,

§

impl<T, U> RefUnwindSafe for BitFlags<T, U>

§

impl<T, U> Send for BitFlags<T, U>
where T: Send, PhantomData<fn() -> *const U>: Send, U: ?Sized,

§

impl<T, U> Sync for BitFlags<T, U>
where T: Sync, PhantomData<fn() -> *const U>: Sync, U: ?Sized,

§

impl<T, U> Unpin for BitFlags<T, U>
where T: Unpin, PhantomData<fn() -> *const U>: Unpin, U: ?Sized,

§

impl<T, U> UnsafeUnpin for BitFlags<T, U>

§

impl<T, U> UnwindSafe for BitFlags<T, U>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.