pub struct EnumSet<T>where
T: EnumSetType,{ /* private fields */ }Expand description
An efficient set type for enums.
It is implemented using a bitset stored using the smallest integer that can fit all bits
in the underlying enum. In general, an enum variant with a discriminant of n is stored in
the nth least significant bit (corresponding with a mask of, e.g. 1 << enum as u32).
§Numeric Representation
EnumSet is internally implemented using integer types, and as such can be easily converted
from and to numbers.
Each bit of the underlying integer corresponds to at most one particular enum variant. If the corresponding bit for a variant is set, it is present in the set. Bits that do not correspond to any variant are always unset.
By default, each enum variant is stored in a bit corresponding to its discriminant. An enum
variant with a discriminant of n is stored in the n + 1th least significant bit
(corresponding to a mask of, e.g. 1 << enum as u32).
The #[enumset(map = "…")] attribute can be used
to control this mapping.
§Array Representation
Sets with 64 or more variants are instead stored with an underlying array of u64s. This is
treated as if it was a single large integer. The nth least significant bit of this integer
is stored in the n % 64th least significant bit of the n / 64th element in the array.
§Serialization
When the serde feature is enabled, EnumSets can be serialized and deserialized using
the serde crate.
By default, EnumSet is serialized by directly writing out a single integer containing the
numeric representation of the bitset. The integer type used is the smallest one that can fit
the largest variant in the enum. If no integer type is large enough, instead the EnumSet is
serialized as an array of u64s containing the array representation. Unknown bits are ignored
and silently removed from the bitset when deserializing.
The exact serialization format can be controlled with additional attributes on the enum type. For more information, see the documentation for Serialization Options.
§FFI Safety
By default, there are no guarantees about the underlying representation of an EnumSet. To use
them safely across FFI boundaries, the
#[enumset(repr = "…")] attribute must be
used with a primitive integer type. For example:
extern "C" {
// This function is written in C like:
// uint32_t some_foreign_function(uint32_t set) { … }
fn some_foreign_function(set: EnumSet<MyEnum>) -> EnumSet<MyEnum>;
}
#[derive(Debug, EnumSetType)]
#[enumset(repr = "u32")]
enum MyEnum { A, B, C }
let set: EnumSet<MyEnum> = enum_set!(MyEnum::A | MyEnum::C);
let new_set: EnumSet<MyEnum> = unsafe { some_foreign_function(set) };
assert_eq!(new_set, enum_set!(MyEnum::C));When an EnumSet<T> is received via FFI, all bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set to 1.
Implementations§
Source§impl<T> EnumSet<T>where
T: EnumSetType,
impl<T> EnumSet<T>where
T: EnumSetType,
Sourcepub const fn empty() -> EnumSet<T>
pub const fn empty() -> EnumSet<T>
Creates an empty EnumSet.
This is an alias for EnumSet::new.
Sourcepub const fn bit_width() -> u32
pub const fn bit_width() -> u32
Total number of bits used by this type. Note that the actual amount of space used is
rounded up to the next highest integer type (u8, u16, u32, u64, or u128).
This is the same as EnumSet::variant_count except in enums with “sparse” variants.
(e.g. enum Foo { A = 10, B = 20 })
Sourcepub const fn variant_count() -> u32
pub const fn variant_count() -> u32
The number of valid variants that this type can contain.
This is the same as EnumSet::bit_width except in enums with “sparse” variants.
(e.g. enum Foo { A = 10, B = 20 })
Sourcepub fn bit_index(t: T) -> u32
pub fn bit_index(t: T) -> u32
Returns the bit a given enum variant is stored in.
If this returns n, it means the bit is stored in the nth least significant bit of the
underlying integer.
Sourcepub fn is_bit_valid(bit: u32) -> bool
pub fn is_bit_valid(bit: u32) -> bool
Returns whether a given bit is valid for this set.
Sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Adds a value to this set.
If the set did not have this value present, true is returned.
If the set did have this value present, false is returned.
Sourcepub fn remove(&mut self, value: T) -> bool
pub fn remove(&mut self, value: T) -> bool
Removes a value from this set. Returns whether the value was present in the set.
Sourcepub fn is_disjoint(&self, other: impl Into<EnumSet<T>>) -> bool
pub fn is_disjoint(&self, other: impl Into<EnumSet<T>>) -> bool
Returns true if self has no elements in common with other. This is equivalent to
checking for an empty intersection.
Sourcepub fn is_superset(&self, other: impl Into<EnumSet<T>>) -> bool
pub fn is_superset(&self, other: impl Into<EnumSet<T>>) -> bool
Returns true if the set is a superset of another, i.e., self contains at least all the
values in other.
Sourcepub fn is_subset(&self, other: impl Into<EnumSet<T>>) -> bool
pub fn is_subset(&self, other: impl Into<EnumSet<T>>) -> bool
Returns true if the set is a subset of another, i.e., other contains at least all
the values in self.
Sourcepub fn union(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
pub fn union(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
Returns a set containing any elements present in either set.
Sourcepub fn intersection(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
pub fn intersection(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
Returns a set containing every element present in both sets.
Sourcepub fn difference(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
pub fn difference(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
Returns a set containing every element present in self but not in other.
Sourcepub fn symmetrical_difference(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
pub fn symmetrical_difference(&self, other: impl Into<EnumSet<T>>) -> EnumSet<T>
Returns a set containing every element present in either self or other, but not
present in both.
Sourcepub fn complement(&self) -> EnumSet<T>
pub fn complement(&self) -> EnumSet<T>
Returns a set containing all enum variants not in this set.
Sourcepub fn insert_all(&mut self, other: EnumSet<T>)
pub fn insert_all(&mut self, other: EnumSet<T>)
Adds all elements in another set to this one.
Sourcepub fn remove_all(&mut self, other: EnumSet<T>)
pub fn remove_all(&mut self, other: EnumSet<T>)
Removes all values in another set from this one.
Source§impl<T> EnumSet<T>where
T: EnumSetType,
This impl contains all outdated or deprecated functions.
impl<T> EnumSet<T>where
T: EnumSetType,
This impl contains all outdated or deprecated functions.
Sourcepub const EMPTY: EnumSet<T> = Self::EMPTY_REPR
👎Deprecated: Use EnumSet::empty() instead.
pub const EMPTY: EnumSet<T> = Self::EMPTY_REPR
Use EnumSet::empty() instead.
An empty EnumSet.
This is deprecated because EnumSet::empty is now const.
Sourcepub const ALL: EnumSet<T> = Self::ALL_REPR
👎Deprecated: Use EnumSet::all() instead.
pub const ALL: EnumSet<T> = Self::ALL_REPR
Use EnumSet::all() instead.
An EnumSet containing all valid variants of the enum.
This is deprecated because EnumSet::all is now const.
Source§impl<T> EnumSet<T>where
T: EnumSetType + EnumSetTypeWithRepr,
impl<T> EnumSet<T>where
T: EnumSetType + EnumSetTypeWithRepr,
Sourcepub const fn as_repr(&self) -> <T as EnumSetTypeWithRepr>::Repr
pub const fn as_repr(&self) -> <T as EnumSetTypeWithRepr>::Repr
Returns a T::Repr representing the elements of this set.
Unlike the other as_* methods, this method is zero-cost and guaranteed not to fail,
panic or truncate any bits.
In order to use this method, the definition of T must have an
#[enumset(repr = "…")] annotation
with a primitive integer type.
Sourcepub unsafe fn from_repr_unchecked(
bits: <T as EnumSetTypeWithRepr>::Repr,
) -> EnumSet<T>
pub unsafe fn from_repr_unchecked( bits: <T as EnumSetTypeWithRepr>::Repr, ) -> EnumSet<T>
Constructs a bitset from a T::Repr without checking for invalid bits.
Unlike the other from_* methods, this method is zero-cost and guaranteed not to fail,
panic or truncate any bits, provided the conditions under “Safety” are upheld.
In order to use this method, the definition of T must have an
#[enumset(repr = "…")] annotation
with a primitive integer type.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant of
T must be set to 0. Behavior is undefined if any of these bits are set to 1.
Sourcepub fn from_repr(bits: <T as EnumSetTypeWithRepr>::Repr) -> EnumSet<T>
pub fn from_repr(bits: <T as EnumSetTypeWithRepr>::Repr) -> EnumSet<T>
Constructs a bitset from a T::Repr.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
In order to use this method, the definition of T must have an
#[enumset(repr = "…")] annotation
with a primitive integer type.
Sourcepub fn try_from_repr(
bits: <T as EnumSetTypeWithRepr>::Repr,
) -> Option<EnumSet<T>>
pub fn try_from_repr( bits: <T as EnumSetTypeWithRepr>::Repr, ) -> Option<EnumSet<T>>
Attempts to construct a bitset from a T::Repr.
If a bit that doesn’t correspond to an enum variant is set, this
method will return None.
In order to use this method, the definition of T must have an
#[enumset(repr = "…")] annotation
with a primitive integer type.
Sourcepub fn from_repr_truncated(bits: <T as EnumSetTypeWithRepr>::Repr) -> EnumSet<T>
pub fn from_repr_truncated(bits: <T as EnumSetTypeWithRepr>::Repr) -> EnumSet<T>
Constructs a bitset from a T::Repr, ignoring invalid variants.
In order to use this method, the definition of T must have an
#[enumset(repr = "…")] annotation
with a primitive integer type.
Source§impl<T> EnumSet<T>where
T: EnumSetType,
impl<T> EnumSet<T>where
T: EnumSetType,
Sourcepub fn as_u8(&self) -> u8
pub fn as_u8(&self) -> u8
Returns a u8 representing the elements of this set.
If the underlying bitset will not fit in a u8, this method will panic.
Sourcepub fn try_as_u8(&self) -> Option<u8>
pub fn try_as_u8(&self) -> Option<u8>
Tries to return a u8 representing the elements of this set.
If the underlying bitset will not fit in a u8, this method will return None.
Sourcepub fn as_u8_truncated(&self) -> u8
pub fn as_u8_truncated(&self) -> u8
Returns a truncated u8 representing the elements of this set.
If the underlying bitset will not fit in a u8, this method will truncate any bits that don’t fit.
Sourcepub fn from_u8(bits: u8) -> EnumSet<T>
pub fn from_u8(bits: u8) -> EnumSet<T>
Constructs a bitset from a u8.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_u8(bits: u8) -> Option<EnumSet<T>>
pub fn try_from_u8(bits: u8) -> Option<EnumSet<T>>
Attempts to construct a bitset from a u8.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_u8_truncated(bits: u8) -> EnumSet<T>
pub fn from_u8_truncated(bits: u8) -> EnumSet<T>
Constructs a bitset from a u8, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_u8_unchecked(bits: u8) -> EnumSet<T>
pub unsafe fn from_u8_unchecked(bits: u8) -> EnumSet<T>
Constructs a bitset from a u8, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn as_u16(&self) -> u16
pub fn as_u16(&self) -> u16
Returns a u16 representing the elements of this set.
If the underlying bitset will not fit in a u16, this method will panic.
Sourcepub fn try_as_u16(&self) -> Option<u16>
pub fn try_as_u16(&self) -> Option<u16>
Tries to return a u16 representing the elements of this set.
If the underlying bitset will not fit in a u16, this method will return None.
Sourcepub fn as_u16_truncated(&self) -> u16
pub fn as_u16_truncated(&self) -> u16
Returns a truncated u16 representing the elements of this set.
If the underlying bitset will not fit in a u16, this method will truncate any bits that don’t fit.
Sourcepub fn from_u16(bits: u16) -> EnumSet<T>
pub fn from_u16(bits: u16) -> EnumSet<T>
Constructs a bitset from a u16.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_u16(bits: u16) -> Option<EnumSet<T>>
pub fn try_from_u16(bits: u16) -> Option<EnumSet<T>>
Attempts to construct a bitset from a u16.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_u16_truncated(bits: u16) -> EnumSet<T>
pub fn from_u16_truncated(bits: u16) -> EnumSet<T>
Constructs a bitset from a u16, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_u16_unchecked(bits: u16) -> EnumSet<T>
pub unsafe fn from_u16_unchecked(bits: u16) -> EnumSet<T>
Constructs a bitset from a u16, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Returns a u32 representing the elements of this set.
If the underlying bitset will not fit in a u32, this method will panic.
Sourcepub fn try_as_u32(&self) -> Option<u32>
pub fn try_as_u32(&self) -> Option<u32>
Tries to return a u32 representing the elements of this set.
If the underlying bitset will not fit in a u32, this method will return None.
Sourcepub fn as_u32_truncated(&self) -> u32
pub fn as_u32_truncated(&self) -> u32
Returns a truncated u32 representing the elements of this set.
If the underlying bitset will not fit in a u32, this method will truncate any bits that don’t fit.
Sourcepub fn from_u32(bits: u32) -> EnumSet<T>
pub fn from_u32(bits: u32) -> EnumSet<T>
Constructs a bitset from a u32.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_u32(bits: u32) -> Option<EnumSet<T>>
pub fn try_from_u32(bits: u32) -> Option<EnumSet<T>>
Attempts to construct a bitset from a u32.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_u32_truncated(bits: u32) -> EnumSet<T>
pub fn from_u32_truncated(bits: u32) -> EnumSet<T>
Constructs a bitset from a u32, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_u32_unchecked(bits: u32) -> EnumSet<T>
pub unsafe fn from_u32_unchecked(bits: u32) -> EnumSet<T>
Constructs a bitset from a u32, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Returns a u64 representing the elements of this set.
If the underlying bitset will not fit in a u64, this method will panic.
Sourcepub fn try_as_u64(&self) -> Option<u64>
pub fn try_as_u64(&self) -> Option<u64>
Tries to return a u64 representing the elements of this set.
If the underlying bitset will not fit in a u64, this method will return None.
Sourcepub fn as_u64_truncated(&self) -> u64
pub fn as_u64_truncated(&self) -> u64
Returns a truncated u64 representing the elements of this set.
If the underlying bitset will not fit in a u64, this method will truncate any bits that don’t fit.
Sourcepub fn from_u64(bits: u64) -> EnumSet<T>
pub fn from_u64(bits: u64) -> EnumSet<T>
Constructs a bitset from a u64.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_u64(bits: u64) -> Option<EnumSet<T>>
pub fn try_from_u64(bits: u64) -> Option<EnumSet<T>>
Attempts to construct a bitset from a u64.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_u64_truncated(bits: u64) -> EnumSet<T>
pub fn from_u64_truncated(bits: u64) -> EnumSet<T>
Constructs a bitset from a u64, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_u64_unchecked(bits: u64) -> EnumSet<T>
pub unsafe fn from_u64_unchecked(bits: u64) -> EnumSet<T>
Constructs a bitset from a u64, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn as_u128(&self) -> u128
pub fn as_u128(&self) -> u128
Returns a u128 representing the elements of this set.
If the underlying bitset will not fit in a u128, this method will panic.
Sourcepub fn try_as_u128(&self) -> Option<u128>
pub fn try_as_u128(&self) -> Option<u128>
Tries to return a u128 representing the elements of this set.
If the underlying bitset will not fit in a u128, this method will return None.
Sourcepub fn as_u128_truncated(&self) -> u128
pub fn as_u128_truncated(&self) -> u128
Returns a truncated u128 representing the elements of this set.
If the underlying bitset will not fit in a u128, this method will truncate any bits that don’t fit.
Sourcepub fn from_u128(bits: u128) -> EnumSet<T>
pub fn from_u128(bits: u128) -> EnumSet<T>
Constructs a bitset from a u128.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_u128(bits: u128) -> Option<EnumSet<T>>
pub fn try_from_u128(bits: u128) -> Option<EnumSet<T>>
Attempts to construct a bitset from a u128.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_u128_truncated(bits: u128) -> EnumSet<T>
pub fn from_u128_truncated(bits: u128) -> EnumSet<T>
Constructs a bitset from a u128, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_u128_unchecked(bits: u128) -> EnumSet<T>
pub unsafe fn from_u128_unchecked(bits: u128) -> EnumSet<T>
Constructs a bitset from a u128, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn as_usize(&self) -> usize
pub fn as_usize(&self) -> usize
Returns a usize representing the elements of this set.
If the underlying bitset will not fit in a usize, this method will panic.
Sourcepub fn try_as_usize(&self) -> Option<usize>
pub fn try_as_usize(&self) -> Option<usize>
Tries to return a usize representing the elements of this set.
If the underlying bitset will not fit in a usize, this method will return None.
Sourcepub fn as_usize_truncated(&self) -> usize
pub fn as_usize_truncated(&self) -> usize
Returns a truncated usize representing the elements of this set.
If the underlying bitset will not fit in a usize, this method will truncate any bits that don’t fit.
Sourcepub fn from_usize(bits: usize) -> EnumSet<T>
pub fn from_usize(bits: usize) -> EnumSet<T>
Constructs a bitset from a usize.
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_usize(bits: usize) -> Option<EnumSet<T>>
pub fn try_from_usize(bits: usize) -> Option<EnumSet<T>>
Attempts to construct a bitset from a usize.
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_usize_truncated(bits: usize) -> EnumSet<T>
pub fn from_usize_truncated(bits: usize) -> EnumSet<T>
Constructs a bitset from a usize, ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_usize_unchecked(bits: usize) -> EnumSet<T>
pub unsafe fn from_usize_unchecked(bits: usize) -> EnumSet<T>
Constructs a bitset from a usize, without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Source§impl<T> EnumSet<T>where
T: EnumSetType,
impl<T> EnumSet<T>where
T: EnumSetType,
Sourcepub fn as_array<const O: usize>(&self) -> [u64; O]
pub fn as_array<const O: usize>(&self) -> [u64; O]
Returns a [u64; O] representing the elements of this set.
If the underlying bitset will not fit in a [u64; O], this method will panic.
Sourcepub fn try_as_array<const O: usize>(&self) -> Option<[u64; O]>
pub fn try_as_array<const O: usize>(&self) -> Option<[u64; O]>
Returns a [u64; O] representing the elements of this set.
If the underlying bitset will not fit in a [u64; O], this method will instead return
None.
Sourcepub fn as_array_truncated<const O: usize>(&self) -> [u64; O]
pub fn as_array_truncated<const O: usize>(&self) -> [u64; O]
Returns a [u64; O] representing the elements of this set.
If the underlying bitset will not fit in a [u64; O], this method will truncate any bits
that don’t fit.
Sourcepub fn from_array<const O: usize>(v: [u64; O]) -> EnumSet<T>
pub fn from_array<const O: usize>(v: [u64; O]) -> EnumSet<T>
Constructs a bitset from a [u64; O].
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_array<const O: usize>(bits: [u64; O]) -> Option<EnumSet<T>>
pub fn try_from_array<const O: usize>(bits: [u64; O]) -> Option<EnumSet<T>>
Attempts to construct a bitset from a [u64; O].
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_array_truncated<const O: usize>(bits: [u64; O]) -> EnumSet<T>
pub fn from_array_truncated<const O: usize>(bits: [u64; O]) -> EnumSet<T>
Constructs a bitset from a [u64; O], ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_array_unchecked<const O: usize>(bits: [u64; O]) -> EnumSet<T>
pub unsafe fn from_array_unchecked<const O: usize>(bits: [u64; O]) -> EnumSet<T>
Constructs a bitset from a [u64; O], without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Sourcepub fn copy_into_slice(&self, data: &mut [u64])
pub fn copy_into_slice(&self, data: &mut [u64])
Copies the elements of this set into a &mut [u64].
If the underlying bitset will not fit in the provided slice, this method will panic.
Sourcepub fn try_copy_into_slice(&self, data: &mut [u64]) -> Option<()>
pub fn try_copy_into_slice(&self, data: &mut [u64]) -> Option<()>
Copies the elements of this set into a &mut [u64].
If the underlying bitset will not fit in the provided slice, this method will return
None. Otherwise, it will return Some(()).
Sourcepub fn copy_into_slice_truncated(&self, data: &mut [u64])
pub fn copy_into_slice_truncated(&self, data: &mut [u64])
Copies the elements of this set into a &mut [u64].
If the underlying bitset will not fit in the provided slice, this method will truncate any bits that don’t fit.
Sourcepub fn from_slice(v: &[u64]) -> EnumSet<T>
pub fn from_slice(v: &[u64]) -> EnumSet<T>
Constructs a bitset from a &[u64].
If a bit that doesn’t correspond to an enum variant is set, this method will panic.
Sourcepub fn try_from_slice(bits: &[u64]) -> Option<EnumSet<T>>
pub fn try_from_slice(bits: &[u64]) -> Option<EnumSet<T>>
Attempts to construct a bitset from a &[u64].
If a bit that doesn’t correspond to an enum variant is set, this method will return None.
Sourcepub fn from_slice_truncated(bits: &[u64]) -> EnumSet<T>
pub fn from_slice_truncated(bits: &[u64]) -> EnumSet<T>
Constructs a bitset from a &[u64], ignoring bits that do not correspond to a variant.
Sourcepub unsafe fn from_slice_unchecked(bits: &[u64]) -> EnumSet<T>
pub unsafe fn from_slice_unchecked(bits: &[u64]) -> EnumSet<T>
Constructs a bitset from a &[u64], without checking for invalid bits.
§Safety
All bits in the provided parameter bits that don’t correspond to an enum variant
of T must be set to 0. Behavior is undefined if any of these bits are set
to 1.
Source§impl<T> EnumSet<T>where
T: EnumSetType,
impl<T> EnumSet<T>where
T: EnumSetType,
Sourcepub fn iter(&self) -> EnumSetIter<T>
pub fn iter(&self) -> EnumSetIter<T>
Iterates the contents of the set in order from the least significant bit to the most significant bit.
Note that iterator invalidation is impossible as the iterator contains a copy of this type, rather than holding a reference to it.
Trait Implementations§
Source§impl<T, O> BitAndAssign<O> for EnumSet<T>
impl<T, O> BitAndAssign<O> for EnumSet<T>
Source§fn bitand_assign(&mut self, rhs: O)
fn bitand_assign(&mut self, rhs: O)
&= operation. Read moreSource§impl<T, O> BitOrAssign<O> for EnumSet<T>
impl<T, O> BitOrAssign<O> for EnumSet<T>
Source§fn bitor_assign(&mut self, rhs: O)
fn bitor_assign(&mut self, rhs: O)
|= operation. Read moreSource§impl<T, O> BitXorAssign<O> for EnumSet<T>
impl<T, O> BitXorAssign<O> for EnumSet<T>
Source§fn bitxor_assign(&mut self, rhs: O)
fn bitxor_assign(&mut self, rhs: O)
^= operation. Read moreSource§impl<T> Default for EnumSet<T>where
T: EnumSetType,
impl<T> Default for EnumSet<T>where
T: EnumSetType,
Source§impl<'de, T> Deserialize<'de> for EnumSet<T>where
T: EnumSetType,
Available on crate feature serde only.
impl<'de, T> Deserialize<'de> for EnumSet<T>where
T: EnumSetType,
serde only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<EnumSet<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<EnumSet<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<'a, T> Extend<&'a EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
impl<'a, T> Extend<&'a EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a EnumSet<T>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a EnumSet<T>>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a, T> Extend<&'a T> for EnumSet<T>where
T: EnumSetType,
impl<'a, T> Extend<&'a T> for EnumSet<T>where
T: EnumSetType,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> Extend<EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
impl<T> Extend<EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = EnumSet<T>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = EnumSet<T>>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> Extend<T> for EnumSet<T>where
T: EnumSetType,
impl<T> Extend<T> for EnumSet<T>where
T: EnumSetType,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> From<T> for EnumSet<T>where
T: EnumSetType,
impl<T> From<T> for EnumSet<T>where
T: EnumSetType,
Source§impl<'a, T> FromIterator<&'a EnumSet<T>> for EnumSet<T>where
T: 'a + EnumSetType,
impl<'a, T> FromIterator<&'a EnumSet<T>> for EnumSet<T>where
T: 'a + EnumSetType,
Source§impl<'a, T> FromIterator<&'a T> for EnumSet<T>where
T: 'a + EnumSetType,
impl<'a, T> FromIterator<&'a T> for EnumSet<T>where
T: 'a + EnumSetType,
Source§impl<T> FromIterator<EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
impl<T> FromIterator<EnumSet<T>> for EnumSet<T>where
T: EnumSetType,
Source§impl<T> FromIterator<T> for EnumSet<T>where
T: EnumSetType,
impl<T> FromIterator<T> for EnumSet<T>where
T: EnumSetType,
Source§impl<T> Hash for EnumSet<T>where
T: EnumSetType,
impl<T> Hash for EnumSet<T>where
T: EnumSetType,
Source§impl<T> IntoIterator for EnumSet<T>where
T: EnumSetType,
impl<T> IntoIterator for EnumSet<T>where
T: EnumSetType,
Source§impl<T> Not for EnumSet<T>where
T: EnumSetType,
impl<T> Not for EnumSet<T>where
T: EnumSetType,
Source§impl<T> Ord for EnumSet<T>where
T: EnumSetType,
impl<T> Ord for EnumSet<T>where
T: EnumSetType,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq<EnumSet<AtomicUsage>> for AtomicUsage
impl PartialEq<EnumSet<AtomicUsage>> for AtomicUsage
Source§impl PartialEq<EnumSet<FastMath>> for FastMath
impl PartialEq<EnumSet<FastMath>> for FastMath
Source§impl PartialEq<EnumSet<Plane>> for Plane
impl PartialEq<EnumSet<Plane>> for Plane
Source§impl PartialEq<EnumSet<Tma>> for Tma
impl PartialEq<EnumSet<Tma>> for Tma
Source§impl PartialEq<EnumSet<TypeUsage>> for TypeUsage
impl PartialEq<EnumSet<TypeUsage>> for TypeUsage
Source§impl<T> PartialEq<MixedEnumSet<T>> for EnumSet<T>where
T: EnumSetTypeWithRepr,
impl<T> PartialEq<MixedEnumSet<T>> for EnumSet<T>where
T: EnumSetTypeWithRepr,
Source§fn eq(&self, other: &MixedEnumSet<T>) -> bool
fn eq(&self, other: &MixedEnumSet<T>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T> PartialEq<T> for EnumSet<T>where
T: EnumSetType,
impl<T> PartialEq<T> for EnumSet<T>where
T: EnumSetType,
Source§impl<T> PartialEq for EnumSet<T>
impl<T> PartialEq for EnumSet<T>
Source§impl<T> PartialOrd for EnumSet<T>where
T: EnumSetType,
impl<T> PartialOrd for EnumSet<T>where
T: EnumSetType,
Source§impl<T> Serialize for EnumSet<T>where
T: EnumSetType,
Available on crate feature serde only.
impl<T> Serialize for EnumSet<T>where
T: EnumSetType,
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T, O> SubAssign<O> for EnumSet<T>
impl<T, O> SubAssign<O> for EnumSet<T>
Source§fn sub_assign(&mut self, rhs: O)
fn sub_assign(&mut self, rhs: O)
-= operation. Read moreSource§impl<T> Sum<T> for EnumSet<T>where
T: EnumSetType,
impl<T> Sum<T> for EnumSet<T>where
T: EnumSetType,
Source§impl<T> Sum for EnumSet<T>where
T: EnumSetType,
impl<T> Sum for EnumSet<T>where
T: EnumSetType,
impl<T> Copy for EnumSet<T>
impl<T> Eq for EnumSet<T>
impl<T> StructuralPartialEq for EnumSet<T>where
T: EnumSetType,
Auto Trait Implementations§
impl<T> Freeze for EnumSet<T>where
<T as EnumSetTypePrivate>::Repr: Freeze,
impl<T> RefUnwindSafe for EnumSet<T>where
<T as EnumSetTypePrivate>::Repr: RefUnwindSafe,
impl<T> Send for EnumSet<T>
impl<T> Sync for EnumSet<T>
impl<T> Unpin for EnumSet<T>where
<T as EnumSetTypePrivate>::Repr: Unpin,
impl<T> UnsafeUnpin for EnumSet<T>where
<T as EnumSetTypePrivate>::Repr: UnsafeUnpin,
impl<T> UnwindSafe for EnumSet<T>where
<T as EnumSetTypePrivate>::Repr: UnwindSafe,
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.