pub struct BitFlag<T, U>(/* private fields */)
where
U: ?Sized;Expand description
A single named or indexed bit in a BitFlags set.
A BitFlag stores a bit index and is tied to the same storage type T and
tag type U as the corresponding BitFlags<T, U>.
It is primarily returned by BitFlagsIter and can be combined with other
flags or converted into a BitFlags set.
§Formatting
Display writes the flag’s name if one is defined in
BitFlagsSpec::FLAG_NAMES, and its mask (1 << bit) in lowercase
hexadecimal with a 0x prefix otherwise.
The mask is computed from the bit index regardless of whether the index is
in range for T.
Debug writes the bit index and the type parameters.
Binary, Octal,
LowerHex, and UpperHex write the
mask in the corresponding numeric base.
§Method summary
from_bit_retain(): Return a flag for a bit index, without validation.try_from_bit(): Return a flag for a bit index, rejecting it if invalid.try_from_bits(): Return a flag from a single-bit mask, rejecting it if invalid.try_from_bits_retain(): Return a flag from a single-bit mask, without validation.try_from_flags(): Return a flag from aBitFlagswith exactly one valid bit.try_from_str(): Parse from a name or a hex flag.from_str_opt(): Parse from a name or a hex flag, returningOption.try_from_name(): Parse from a name only.from_name_opt(): Parse from a name only, returningOption.try_from_hex(): Parse from a hex flag only.from_hex_opt(): Parse from a hex flag only, returningOption.bit(): Return the zero-based bit index.mask(): Return the single-bit mask, orNoneif out of range.name(): Return the primary name, if any.name_and_aliases(): Return all names and aliases.is_valid(): Returntrueif the bit is valid for the tag.intersection(): Return the bits set in both flags.union(): Return the bits set in either flag.difference(): Return the bits set inselfbut not inother.symmetric_difference(): Return the bits set in exactly one flag.complement(): Return the valid bits not set inself.
Implementations§
Source§impl<T, U> BitFlag<T, U>where
U: ?Sized,
impl<T, U> BitFlag<T, U>where
U: ?Sized,
Sourcepub const fn from_bit_retain(i: u8) -> Self
pub const fn from_bit_retain(i: u8) -> Self
Creates a bit flag for bit index i.
The index is not checked against the number of bits in T, against
BitFlagsSpec::VALID_BITS_MASK, or against
BitFlagsSpec::FLAG_NAMES.
A BitFlag created with this method may refer to a bit that is out of
range for T or invalid for the tag.
Use BitFlag::try_from_bit or BitFlag::is_valid when validation
is required.
Sourcepub const fn name(&self) -> Option<&'static str>where
U: BitFlagsSpec<T>,
pub const fn name(&self) -> Option<&'static str>where
U: BitFlagsSpec<T>,
Returns the primary name of this bit, if one is defined in
BitFlagsSpec::FLAG_NAMES.
The primary name is the first entry in the inner slice for this bit.
Returns None if the bit has no name.
Sourcepub const fn name_and_aliases(&self) -> &'static [&'static str]where
U: BitFlagsSpec<T>,
pub const fn name_and_aliases(&self) -> &'static [&'static str]where
U: BitFlagsSpec<T>,
Returns all names and aliases for this bit.
The returned slice is the entry at this bit’s index in
BitFlagsSpec::FLAG_NAMES, or an empty slice if the index is out of
range or the bit has no names.
Sourcepub fn try_from_str(
input: &str,
name_matcher: NameMatcher,
) -> Result<Self, BitFlagParseError>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
pub fn try_from_str(
input: &str,
name_matcher: NameMatcher,
) -> Result<Self, BitFlagParseError>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
Parses a single flag from input using name_matcher.
This is equivalent to BitFlag::try_from_str, but returns a
BitFlagParseError describing the input and expected names on
failure.
§Errors
Returns BitFlagParseError if input is neither a recognized named
flag nor a hexadecimal flag of the form 0x... with exactly one bit
set.
Sourcepub fn from_str_opt(input: &str, name_matcher: NameMatcher) -> Option<Self>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
pub fn from_str_opt(input: &str, name_matcher: NameMatcher) -> Option<Self>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
Parses a single flag from input using name_matcher.
The input is first matched against the names and aliases in
BitFlagsSpec::FLAG_NAMES. If no name matches, it is parsed as a
hexadecimal flag with a 0x prefix that must have exactly one bit set.
Returns None if input is not recognized.
Sourcepub fn try_from_name(
input: &str,
name_matcher: NameMatcher,
) -> Result<Self, BitFlagParseNameError>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
pub fn try_from_name(
input: &str,
name_matcher: NameMatcher,
) -> Result<Self, BitFlagParseNameError>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
Parses a named flag from input using name_matcher.
This is equivalent to BitFlag::try_from_name, but returns a
BitFlagParseNameError describing the input and expected names on
failure.
§Errors
Returns BitFlagParseNameError if input does not match any name or
alias in BitFlagsSpec::FLAG_NAMES.
Sourcepub fn from_name_opt(input: &str, name_matcher: NameMatcher) -> Option<Self>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
pub fn from_name_opt(input: &str, name_matcher: NameMatcher) -> Option<Self>where
T: IntOpsExt,
U: BitFlagsSpec<T>,
Parses a named flag from input using name_matcher.
The input is matched against all names and aliases in
BitFlagsSpec::FLAG_NAMES.
Returns None if no name matches.
Sourcepub fn try_from_hex(input: &str) -> Result<Self, BitFlagParseHexError>where
T: IntOpsExt,
pub fn try_from_hex(input: &str) -> Result<Self, BitFlagParseHexError>where
T: IntOpsExt,
Parses a hexadecimal flag from input.
This is equivalent to BitFlag::try_from_hex, but returns a
BitFlagParseHexError describing the input on failure.
§Errors
Returns BitFlagParseHexError if input is not a valid 0x-prefixed
hexadecimal flag with exactly one bit set.
Sourcepub fn from_hex_opt(input: &str) -> Option<Self>where
T: IntOpsExt,
pub fn from_hex_opt(input: &str) -> Option<Self>where
T: IntOpsExt,
Parses a hexadecimal flag from input.
The input must have a 0x prefix and represent a value with exactly one
bit set.
A leading + is not accepted.
Returns None if input is not a valid hexadecimal flag.
Source§impl<U> BitFlag<u8, U>where
U: ?Sized,
impl<U> BitFlag<u8, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<u8, U>) -> Option<Self>where
U: BitFlagsSpec<u8>,
pub const fn try_from_flags(flags: BitFlags<u8, U>) -> Option<Self>where
U: BitFlagsSpec<u8>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u8>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u8>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: u8) -> Option<Self>where
U: BitFlagsSpec<u8>,
pub const fn try_from_bits(bits: u8) -> Option<Self>where
U: BitFlagsSpec<u8>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: u8) -> Option<Self>
pub const fn try_from_bits_retain(bits: u8) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u8>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u8>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<u8>
pub const fn mask(&self) -> Option<u8>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<u8, U>
pub const fn intersection(self, other: Self) -> BitFlags<u8, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<u8, U>
pub const fn union(self, other: Self) -> BitFlags<u8, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<u8, U>
pub const fn difference(self, other: Self) -> BitFlags<u8, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<u8, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<u8, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<u8, U>where
U: BitFlagsSpec<u8>,
pub const fn complement(self) -> BitFlags<u8, U>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> BitFlag<u16, U>where
U: ?Sized,
impl<U> BitFlag<u16, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<u16, U>) -> Option<Self>where
U: BitFlagsSpec<u16>,
pub const fn try_from_flags(flags: BitFlags<u16, U>) -> Option<Self>where
U: BitFlagsSpec<u16>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u16>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u16>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: u16) -> Option<Self>where
U: BitFlagsSpec<u16>,
pub const fn try_from_bits(bits: u16) -> Option<Self>where
U: BitFlagsSpec<u16>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: u16) -> Option<Self>
pub const fn try_from_bits_retain(bits: u16) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u16>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u16>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<u16>
pub const fn mask(&self) -> Option<u16>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<u16, U>
pub const fn intersection(self, other: Self) -> BitFlags<u16, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<u16, U>
pub const fn union(self, other: Self) -> BitFlags<u16, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<u16, U>
pub const fn difference(self, other: Self) -> BitFlags<u16, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<u16, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<u16, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<u16, U>where
U: BitFlagsSpec<u16>,
pub const fn complement(self) -> BitFlags<u16, U>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> BitFlag<u32, U>where
U: ?Sized,
impl<U> BitFlag<u32, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<u32, U>) -> Option<Self>where
U: BitFlagsSpec<u32>,
pub const fn try_from_flags(flags: BitFlags<u32, U>) -> Option<Self>where
U: BitFlagsSpec<u32>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u32>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u32>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: u32) -> Option<Self>where
U: BitFlagsSpec<u32>,
pub const fn try_from_bits(bits: u32) -> Option<Self>where
U: BitFlagsSpec<u32>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: u32) -> Option<Self>
pub const fn try_from_bits_retain(bits: u32) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u32>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u32>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<u32>
pub const fn mask(&self) -> Option<u32>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<u32, U>
pub const fn intersection(self, other: Self) -> BitFlags<u32, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<u32, U>
pub const fn union(self, other: Self) -> BitFlags<u32, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<u32, U>
pub const fn difference(self, other: Self) -> BitFlags<u32, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<u32, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<u32, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<u32, U>where
U: BitFlagsSpec<u32>,
pub const fn complement(self) -> BitFlags<u32, U>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> BitFlag<u64, U>where
U: ?Sized,
impl<U> BitFlag<u64, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<u64, U>) -> Option<Self>where
U: BitFlagsSpec<u64>,
pub const fn try_from_flags(flags: BitFlags<u64, U>) -> Option<Self>where
U: BitFlagsSpec<u64>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u64>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u64>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: u64) -> Option<Self>where
U: BitFlagsSpec<u64>,
pub const fn try_from_bits(bits: u64) -> Option<Self>where
U: BitFlagsSpec<u64>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: u64) -> Option<Self>
pub const fn try_from_bits_retain(bits: u64) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u64>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u64>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<u64>
pub const fn mask(&self) -> Option<u64>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<u64, U>
pub const fn intersection(self, other: Self) -> BitFlags<u64, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<u64, U>
pub const fn union(self, other: Self) -> BitFlags<u64, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<u64, U>
pub const fn difference(self, other: Self) -> BitFlags<u64, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<u64, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<u64, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<u64, U>where
U: BitFlagsSpec<u64>,
pub const fn complement(self) -> BitFlags<u64, U>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> BitFlag<u128, U>where
U: ?Sized,
impl<U> BitFlag<u128, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<u128, U>) -> Option<Self>where
U: BitFlagsSpec<u128>,
pub const fn try_from_flags(flags: BitFlags<u128, U>) -> Option<Self>where
U: BitFlagsSpec<u128>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u128>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<u128>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: u128) -> Option<Self>where
U: BitFlagsSpec<u128>,
pub const fn try_from_bits(bits: u128) -> Option<Self>where
U: BitFlagsSpec<u128>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: u128) -> Option<Self>
pub const fn try_from_bits_retain(bits: u128) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u128>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<u128>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<u128>
pub const fn mask(&self) -> Option<u128>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<u128, U>
pub const fn intersection(self, other: Self) -> BitFlags<u128, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<u128, U>
pub const fn union(self, other: Self) -> BitFlags<u128, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<u128, U>
pub const fn difference(self, other: Self) -> BitFlags<u128, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<u128, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<u128, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<u128, U>where
U: BitFlagsSpec<u128>,
pub const fn complement(self) -> BitFlags<u128, U>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> BitFlag<usize, U>where
U: ?Sized,
impl<U> BitFlag<usize, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<usize, U>) -> Option<Self>where
U: BitFlagsSpec<usize>,
pub const fn try_from_flags(flags: BitFlags<usize, U>) -> Option<Self>where
U: BitFlagsSpec<usize>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<usize>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<usize>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: usize) -> Option<Self>where
U: BitFlagsSpec<usize>,
pub const fn try_from_bits(bits: usize) -> Option<Self>where
U: BitFlagsSpec<usize>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: usize) -> Option<Self>
pub const fn try_from_bits_retain(bits: usize) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<usize>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<usize>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<usize>
pub const fn mask(&self) -> Option<usize>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<usize, U>
pub const fn intersection(self, other: Self) -> BitFlags<usize, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<usize, U>
pub const fn union(self, other: Self) -> BitFlags<usize, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<usize, U>
pub const fn difference(self, other: Self) -> BitFlags<usize, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<usize, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<usize, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<usize, U>where
U: BitFlagsSpec<usize>,
pub const fn complement(self) -> BitFlags<usize, U>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> BitFlag<i8, U>where
U: ?Sized,
impl<U> BitFlag<i8, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<i8, U>) -> Option<Self>where
U: BitFlagsSpec<i8>,
pub const fn try_from_flags(flags: BitFlags<i8, U>) -> Option<Self>where
U: BitFlagsSpec<i8>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i8>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i8>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: i8) -> Option<Self>where
U: BitFlagsSpec<i8>,
pub const fn try_from_bits(bits: i8) -> Option<Self>where
U: BitFlagsSpec<i8>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: i8) -> Option<Self>
pub const fn try_from_bits_retain(bits: i8) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i8>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i8>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<i8>
pub const fn mask(&self) -> Option<i8>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<i8, U>
pub const fn intersection(self, other: Self) -> BitFlags<i8, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<i8, U>
pub const fn union(self, other: Self) -> BitFlags<i8, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<i8, U>
pub const fn difference(self, other: Self) -> BitFlags<i8, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<i8, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<i8, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<i8, U>where
U: BitFlagsSpec<i8>,
pub const fn complement(self) -> BitFlags<i8, U>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> BitFlag<i16, U>where
U: ?Sized,
impl<U> BitFlag<i16, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<i16, U>) -> Option<Self>where
U: BitFlagsSpec<i16>,
pub const fn try_from_flags(flags: BitFlags<i16, U>) -> Option<Self>where
U: BitFlagsSpec<i16>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i16>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i16>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: i16) -> Option<Self>where
U: BitFlagsSpec<i16>,
pub const fn try_from_bits(bits: i16) -> Option<Self>where
U: BitFlagsSpec<i16>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: i16) -> Option<Self>
pub const fn try_from_bits_retain(bits: i16) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i16>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i16>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<i16>
pub const fn mask(&self) -> Option<i16>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<i16, U>
pub const fn intersection(self, other: Self) -> BitFlags<i16, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<i16, U>
pub const fn union(self, other: Self) -> BitFlags<i16, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<i16, U>
pub const fn difference(self, other: Self) -> BitFlags<i16, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<i16, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<i16, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<i16, U>where
U: BitFlagsSpec<i16>,
pub const fn complement(self) -> BitFlags<i16, U>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> BitFlag<i32, U>where
U: ?Sized,
impl<U> BitFlag<i32, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<i32, U>) -> Option<Self>where
U: BitFlagsSpec<i32>,
pub const fn try_from_flags(flags: BitFlags<i32, U>) -> Option<Self>where
U: BitFlagsSpec<i32>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i32>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i32>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: i32) -> Option<Self>where
U: BitFlagsSpec<i32>,
pub const fn try_from_bits(bits: i32) -> Option<Self>where
U: BitFlagsSpec<i32>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: i32) -> Option<Self>
pub const fn try_from_bits_retain(bits: i32) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i32>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i32>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<i32>
pub const fn mask(&self) -> Option<i32>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<i32, U>
pub const fn intersection(self, other: Self) -> BitFlags<i32, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<i32, U>
pub const fn union(self, other: Self) -> BitFlags<i32, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<i32, U>
pub const fn difference(self, other: Self) -> BitFlags<i32, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<i32, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<i32, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<i32, U>where
U: BitFlagsSpec<i32>,
pub const fn complement(self) -> BitFlags<i32, U>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> BitFlag<i64, U>where
U: ?Sized,
impl<U> BitFlag<i64, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<i64, U>) -> Option<Self>where
U: BitFlagsSpec<i64>,
pub const fn try_from_flags(flags: BitFlags<i64, U>) -> Option<Self>where
U: BitFlagsSpec<i64>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i64>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i64>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: i64) -> Option<Self>where
U: BitFlagsSpec<i64>,
pub const fn try_from_bits(bits: i64) -> Option<Self>where
U: BitFlagsSpec<i64>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: i64) -> Option<Self>
pub const fn try_from_bits_retain(bits: i64) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i64>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i64>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<i64>
pub const fn mask(&self) -> Option<i64>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<i64, U>
pub const fn intersection(self, other: Self) -> BitFlags<i64, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<i64, U>
pub const fn union(self, other: Self) -> BitFlags<i64, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<i64, U>
pub const fn difference(self, other: Self) -> BitFlags<i64, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<i64, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<i64, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<i64, U>where
U: BitFlagsSpec<i64>,
pub const fn complement(self) -> BitFlags<i64, U>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> BitFlag<i128, U>where
U: ?Sized,
impl<U> BitFlag<i128, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<i128, U>) -> Option<Self>where
U: BitFlagsSpec<i128>,
pub const fn try_from_flags(flags: BitFlags<i128, U>) -> Option<Self>where
U: BitFlagsSpec<i128>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i128>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<i128>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: i128) -> Option<Self>where
U: BitFlagsSpec<i128>,
pub const fn try_from_bits(bits: i128) -> Option<Self>where
U: BitFlagsSpec<i128>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: i128) -> Option<Self>
pub const fn try_from_bits_retain(bits: i128) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i128>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<i128>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<i128>
pub const fn mask(&self) -> Option<i128>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<i128, U>
pub const fn intersection(self, other: Self) -> BitFlags<i128, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<i128, U>
pub const fn union(self, other: Self) -> BitFlags<i128, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<i128, U>
pub const fn difference(self, other: Self) -> BitFlags<i128, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<i128, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<i128, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<i128, U>where
U: BitFlagsSpec<i128>,
pub const fn complement(self) -> BitFlags<i128, U>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> BitFlag<isize, U>where
U: ?Sized,
impl<U> BitFlag<isize, U>where
U: ?Sized,
Sourcepub const fn try_from_flags(flags: BitFlags<isize, U>) -> Option<Self>where
U: BitFlagsSpec<isize>,
pub const fn try_from_flags(flags: BitFlags<isize, U>) -> Option<Self>where
U: BitFlagsSpec<isize>,
Creates a bit flag from a BitFlags set.
Returns Some if flags contains exactly one set bit and that
bit is valid according to BitFlagsSpec::VALID_BITS_MASK.
Returns None if flags is empty, has more than one bit set,
or the single set bit is not valid.
This is equivalent to BitFlag::try_from_bits on
flags.bits().
Sourcepub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<isize>,
pub const fn try_from_bit(i: u8) -> Option<Self>where
U: BitFlagsSpec<isize>,
Creates a validated bit flag for bit index i.
Returns None if i is not set in
BitFlagsSpec::VALID_BITS_MASK.
The index i must be less than the number of bits in the
storage type.
Sourcepub const fn try_from_bits(bits: isize) -> Option<Self>where
U: BitFlagsSpec<isize>,
pub const fn try_from_bits(bits: isize) -> Option<Self>where
U: BitFlagsSpec<isize>,
Creates a validated bit flag from bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is zero, has more than one bit set, or
the single set bit is not valid.
Sourcepub const fn try_from_bits_retain(bits: isize) -> Option<Self>
pub const fn try_from_bits_retain(bits: isize) -> Option<Self>
Creates a single-bit flag from bits if exactly one bit is set.
The single set bit is not checked against
BitFlagsSpec::VALID_BITS_MASK.
Returns None if bits is 0 or has more than one bit set.
Sourcepub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<isize>,
pub const fn is_valid(&self) -> boolwhere
U: BitFlagsSpec<isize>,
Returns true if this flag refers to a valid bit.
A flag is valid when its bit index is within the width of T and the
corresponding bit is present in BitFlagsSpec::VALID_BITS_MASK.
BitFlag::from_bit_retain does not validate the bit index, so a
BitFlag constructed through it may be invalid.
Sourcepub const fn mask(&self) -> Option<isize>
pub const fn mask(&self) -> Option<isize>
Returns the single-bit mask for this flag, or None if the bit index is
outside the width of T.
The mask is 1 << bit. It is not checked against
BitFlagsSpec::VALID_BITS_MASK; use BitFlag::is_valid when tag
validity is required.
Sourcepub const fn intersection(self, other: Self) -> BitFlags<isize, U>
pub const fn intersection(self, other: Self) -> BitFlags<isize, U>
Returns the intersection of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved when they are set in both operands.
Sourcepub const fn union(self, other: Self) -> BitFlags<isize, U>
pub const fn union(self, other: Self) -> BitFlags<isize, U>
Returns the union of self and other.
This is a raw-bit operation. Invalid bits in either operand are preserved.
Sourcepub const fn difference(self, other: Self) -> BitFlags<isize, U>
pub const fn difference(self, other: Self) -> BitFlags<isize, U>
Returns the difference of self and other.
The result contains bits that are set in self but not in
other.
This is a raw-bit operation.
Invalid bits already present in self are preserved unless they
are also set in other.
Sourcepub const fn symmetric_difference(self, other: Self) -> BitFlags<isize, U>
pub const fn symmetric_difference(self, other: Self) -> BitFlags<isize, U>
Returns the symmetric difference of self and other.
The result contains bits that are set in exactly one of self
or other.
This is a raw-bit operation.
Invalid bits participate and may be preserved.
Sourcepub const fn complement(self) -> BitFlags<isize, U>where
U: BitFlagsSpec<isize>,
pub const fn complement(self) -> BitFlags<isize, U>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 BitFlag<T, U>where
U: ?Sized,
Available on crate feature arbitrary only.
impl<'a, T, U> Arbitrary<'a> for BitFlag<T, U>where
U: ?Sized,
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<T, U> Binary for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in binary.
impl<T, U> Binary for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in binary.
Source§impl<T, U> BitAndAssign<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> BitAndAssign<BitFlag<T, U>> for BitFlags<T, U>
Source§fn bitand_assign(&mut self, rhs: BitFlag<T, U>)
fn bitand_assign(&mut self, rhs: BitFlag<T, U>)
&= operation. Read moreSource§impl<T, U> BitFlagExt<T, U> for BitFlag<T, U>where
U: ?Sized,
impl<T, U> BitFlagExt<T, U> for BitFlag<T, U>where
U: ?Sized,
Source§fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
fn try_from_flags(flags: BitFlags<T, U>) -> Option<Self>
Source§fn try_from_bit(i: u8) -> Option<Self>
fn try_from_bit(i: u8) -> Option<Self>
i. Read moreSource§fn try_from_bits(bits: T) -> Option<Self>
fn try_from_bits(bits: T) -> Option<Self>
bits if exactly one bit is
set and that bit is valid according to
BitFlagsSpec::VALID_BITS_MASK. Read moreSource§fn try_from_bits_retain(bits: T) -> Option<Self>where
T: IntOpsExt,
fn try_from_bits_retain(bits: T) -> Option<Self>where
T: IntOpsExt,
bits if exactly one bit is set. Read moreSource§fn mask(&self) -> Option<T>where
T: IntOpsExt,
fn mask(&self) -> Option<T>where
T: IntOpsExt,
None if the bit index is
outside the width of T. Read moreSource§fn intersection(self, other: Self) -> BitFlags<T, U>
fn intersection(self, other: Self) -> BitFlags<T, U>
Source§fn difference(self, other: Self) -> BitFlags<T, U>
fn difference(self, other: Self) -> BitFlags<T, U>
Source§fn symmetric_difference(self, other: Self) -> BitFlags<T, U>
fn symmetric_difference(self, other: Self) -> BitFlags<T, U>
Source§fn complement(self) -> BitFlags<T, U>
fn complement(self) -> BitFlags<T, U>
self. Read moreSource§impl<T, U> BitOrAssign<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> BitOrAssign<BitFlag<T, U>> for BitFlags<T, U>
Source§fn bitor_assign(&mut self, rhs: BitFlag<T, U>)
fn bitor_assign(&mut self, rhs: BitFlag<T, U>)
|= operation. Read moreSource§impl<T, U> BitXorAssign<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> BitXorAssign<BitFlag<T, U>> for BitFlags<T, U>
Source§fn bitxor_assign(&mut self, rhs: BitFlag<T, U>)
fn bitxor_assign(&mut self, rhs: BitFlag<T, U>)
^= operation. Read moreimpl<T, U> Copy for BitFlag<T, U>where
U: ?Sized,
Source§impl<T, U> Debug for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s bit index and type parameters.
impl<T, U> Debug for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s bit index and type parameters.
Use Display to format the flag’s mask or name instead.
Source§impl<'de, T, U> Deserialize<'de> for BitFlag<T, U>
Available on crate feature serde only.
impl<'de, T, U> Deserialize<'de> for BitFlag<T, U>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T, U> Display for BitFlag<T, U>where
U: ?Sized + BitFlagsSpec<T>,
Formats this flag as its name if one is defined for its bit, or as its
mask (1 << bit) in lowercase hexadecimal with a 0x prefix otherwise.
impl<T, U> Display for BitFlag<T, U>where
U: ?Sized + BitFlagsSpec<T>,
Formats this flag as its name if one is defined for its bit, or as its
mask (1 << bit) in lowercase hexadecimal with a 0x prefix otherwise.
The mask is computed from the bit index regardless of whether the index
is in range for T. See BitFlag::is_valid.
impl<T, U> Eq for BitFlag<T, U>where
U: ?Sized,
Source§impl<T, U> Extend<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> Extend<BitFlag<T, U>> for BitFlags<T, U>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = BitFlag<T, U>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = BitFlag<T, U>>,
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, U> FromIterator<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> FromIterator<BitFlag<T, U>> for BitFlags<T, U>
Source§impl<T, U> LowerHex for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in lowercase hexadecimal.
impl<T, U> LowerHex for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in lowercase hexadecimal.
Source§impl<T, U> Octal for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in octal.
impl<T, U> Octal for BitFlag<T, U>where
U: ?Sized,
Formats this flag’s mask (1 << bit) in octal.
Source§impl<T, U> Ord for BitFlag<T, U>where
U: ?Sized,
impl<T, U> Ord for BitFlag<T, U>where
U: ?Sized,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T, U> PartialOrd for BitFlag<T, U>where
U: ?Sized,
impl<T, U> PartialOrd for BitFlag<T, U>where
U: ?Sized,
Source§impl<T, U> PartialOrd<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> PartialOrd<BitFlag<T, U>> for BitFlags<T, U>
Source§impl<T, U> PartialOrd<BitFlags<T, U>> for BitFlag<T, U>
impl<T, U> PartialOrd<BitFlags<T, U>> for BitFlag<T, U>
impl<T, U> Pod for BitFlag<T, U>where
T: 'static,
U: 'static + ?Sized,
bytemuck only.Source§impl<T, U> Serialize for BitFlag<T, U>where
U: ?Sized + BitFlagsSpec<T>,
Available on crate feature serde only.
impl<T, U> Serialize for BitFlag<T, U>where
U: ?Sized + BitFlagsSpec<T>,
serde only.Source§impl<T, U> SubAssign<BitFlag<T, U>> for BitFlags<T, U>
impl<T, U> SubAssign<BitFlag<T, U>> for BitFlags<T, U>
Source§fn sub_assign(&mut self, rhs: BitFlag<T, U>)
fn sub_assign(&mut self, rhs: BitFlag<T, U>)
-= operation. Read moreSource§impl<T, U> TryFrom<BitFlags<T, U>> for BitFlag<T, U>
Converts a flag set into a single-bit flag.
impl<T, U> TryFrom<BitFlags<T, U>> for BitFlag<T, U>
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.
Auto Trait Implementations§
impl<T, U> Freeze for BitFlag<T, U>
impl<T, U> RefUnwindSafe for BitFlag<T, U>where
PhantomData<fn() -> T>: RefUnwindSafe,
PhantomData<fn() -> *const U>: RefUnwindSafe,
U: ?Sized,
impl<T, U> Send for BitFlag<T, U>
impl<T, U> Sync for BitFlag<T, U>
impl<T, U> Unpin for BitFlag<T, U>
impl<T, U> UnsafeUnpin for BitFlag<T, U>
impl<T, U> UnwindSafe for BitFlag<T, U>
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.