pub struct BigEnumSet<T: BigEnumSetType> { /* private fields */ }Expand description
An efficient set type for enums.
It is implemented using a bitset stored as [usize; N], where N is the smallest number that
such that the array can fit all the bits of the underlying enum. An enum with discriminant n
is stored in the n / WORD_SIZE word at the n % WORD_SIZE least significant bit (corresponding
with as bit mask of 1 << (n % WORD_SIZE). WORD_SIZE is mem::size_of::<usize>().
§Serialization
When the serde feature is enabled, BigEnumSets can be serialized and deserialized using
the serde crate. The exact serialization format can be controlled
with additional attributes on the enum type. These attributes are valid regardless of
whether the serde feature is enabled.
By default BigEnumSets are serialized as [u8; N], where N is smallest such that the array
can fit all bits that are part of the underlying enum. An enum with discriminant n is serialized
as n % 8th least significant bit in the n / 8 byte. You can add a
#[big_enum_set(serialize_bytes = N)] attribute to your enum to control the number of bytes
in the serialization. This can be important for avoiding unintentional breaking changes when
BigEnumSets are serialized with formats like bincode.
By default, unknown bits are ignored and silently removed from the bitset. To override this
behavior, you can add a #[big_enum_set(serialize_deny_unknown)] attribute. This will cause
deserialization to fail if an invalid bit is set.
In addition, the #[big_enum_set(serialize_as_list)] attribute causes the BigEnumSet to be
instead serialized as a list of enum variants. This requires your enum type implement
Serialize and Deserialize. Note that this is a breaking change.
Implementations§
Source§impl<T: BigEnumSetType> BigEnumSet<T>
impl<T: BigEnumSetType> BigEnumSet<T>
Sourcepub const EMPTY: BigEnumSet<T>
pub const EMPTY: BigEnumSet<T>
Empty set.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates an empty BigEnumSet.
This is an alias for BigEnumSet::new.
Sourcepub fn bit_width() -> u32
pub 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 usize.
This is the same as BigEnumSet::variant_count except in enums with “sparse” variants.
(e.g. enum Foo { A = 10, B = 20 })
Sourcepub fn variant_count() -> u32
pub fn variant_count() -> u32
The number of valid variants this type may contain.
This is the same as BigEnumSet::bit_width except in enums with “sparse” variants.
(e.g. enum Foo { A = 10, B = 20 })
Sourcepub fn try_from_bits(bits: &[usize]) -> Option<Self>
pub fn try_from_bits(bits: &[usize]) -> Option<Self>
Constructs a BigEnumSet from raw bits.
Returns None if there are any invalid bits set in bits.
The size of bits need not match the underlying representation.
Sourcepub fn from_bits_truncated(bits: &[usize]) -> Self
pub fn from_bits_truncated(bits: &[usize]) -> Self
Constructs a BigEnumSet from raw bits, ignoring any unknown variants.
The size of bits need not match the underlying representation.
Sourcepub fn is_disjoint<O: Borrow<Self>>(&self, other: O) -> bool
pub fn is_disjoint<O: Borrow<Self>>(&self, other: O) -> 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<O: Borrow<Self>>(&self, other: O) -> bool
pub fn is_superset<O: Borrow<Self>>(&self, other: O) -> bool
Returns true if self is a superset of other, i.e., self contains at least all the
elements in other.
Sourcepub fn is_subset<O: Borrow<Self>>(&self, other: O) -> bool
pub fn is_subset<O: Borrow<Self>>(&self, other: O) -> bool
Returns true if self is a subset of other, i.e., other contains at least all
the elements in self.
Sourcepub fn union<O: Borrow<Self>>(&self, other: O) -> Self
pub fn union<O: Borrow<Self>>(&self, other: O) -> Self
Returns a set containing all elements present in either set.
Sourcepub fn intersection<O: Borrow<Self>>(&self, other: O) -> Self
pub fn intersection<O: Borrow<Self>>(&self, other: O) -> Self
Returns a set containing all elements present in both sets.
Sourcepub fn difference<O: Borrow<Self>>(&self, other: O) -> Self
pub fn difference<O: Borrow<Self>>(&self, other: O) -> Self
Returns a set containing all elements present in self but not in other.
Sourcepub fn symmetrical_difference<O: Borrow<Self>>(&self, other: O) -> Self
pub fn symmetrical_difference<O: Borrow<Self>>(&self, other: O) -> Self
Returns a set containing all elements present in either self or other, but is not present
in both.
Sourcepub fn complement(&self) -> Self
pub fn complement(&self) -> Self
Returns a set containing all enum variants not present in 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 insert_all<O: Borrow<Self>>(&mut self, other: O)
pub fn insert_all<O: Borrow<Self>>(&mut self, other: O)
Adds all elements in another set to this one.
Sourcepub fn remove_all<O: Borrow<Self>>(&mut self, other: O)
pub fn remove_all<O: Borrow<Self>>(&mut self, other: O)
Removes all values in another set from this one.
Sourcepub fn iter(&self) -> EnumSetIter<&BigEnumSet<T>, T> ⓘ
pub fn iter(&self) -> EnumSetIter<&BigEnumSet<T>, T> ⓘ
Creates an iterator over the values in this set.
Trait Implementations§
Source§impl<T: BigEnumSetType> BitAnd<&BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd<&BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
& operator.Source§impl<T: BigEnumSetType> BitAnd<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd<&BigEnumSet<T>> for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
& operator.Source§impl<T: BigEnumSetType> BitAnd<BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd<BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
& operator.Source§impl<T: BigEnumSetType> BitAnd<T> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd<T> for &BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitAnd<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd<T> for BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitAnd for BigEnumSet<T>
impl<T: BigEnumSetType> BitAnd for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
& operator.Source§impl<T: BigEnumSetType> BitAndAssign<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitAndAssign<&BigEnumSet<T>> for BigEnumSet<T>
Source§fn bitand_assign(&mut self, other: &BigEnumSet<T>)
fn bitand_assign(&mut self, other: &BigEnumSet<T>)
&= operation. Read moreSource§impl<T: BigEnumSetType> BitAndAssign<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitAndAssign<T> for BigEnumSet<T>
Source§fn bitand_assign(&mut self, value: T)
fn bitand_assign(&mut self, value: T)
&= operation. Read moreSource§impl<T: BigEnumSetType> BitAndAssign for BigEnumSet<T>
impl<T: BigEnumSetType> BitAndAssign for BigEnumSet<T>
Source§fn bitand_assign(&mut self, other: BigEnumSet<T>)
fn bitand_assign(&mut self, other: BigEnumSet<T>)
&= operation. Read moreSource§impl<T: BigEnumSetType> BitOr<&BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitOr<&BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
| operator.Source§impl<T: BigEnumSetType> BitOr<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitOr<&BigEnumSet<T>> for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
| operator.Source§impl<T: BigEnumSetType> BitOr<BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitOr<BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
| operator.Source§impl<T: BigEnumSetType> BitOr<T> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitOr<T> for &BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitOr<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitOr<T> for BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitOr for BigEnumSet<T>
impl<T: BigEnumSetType> BitOr for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
| operator.Source§impl<T: BigEnumSetType> BitOrAssign<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitOrAssign<&BigEnumSet<T>> for BigEnumSet<T>
Source§fn bitor_assign(&mut self, other: &BigEnumSet<T>)
fn bitor_assign(&mut self, other: &BigEnumSet<T>)
|= operation. Read moreSource§impl<T: BigEnumSetType> BitOrAssign<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitOrAssign<T> for BigEnumSet<T>
Source§fn bitor_assign(&mut self, value: T)
fn bitor_assign(&mut self, value: T)
|= operation. Read moreSource§impl<T: BigEnumSetType> BitOrAssign for BigEnumSet<T>
impl<T: BigEnumSetType> BitOrAssign for BigEnumSet<T>
Source§fn bitor_assign(&mut self, other: BigEnumSet<T>)
fn bitor_assign(&mut self, other: BigEnumSet<T>)
|= operation. Read moreSource§impl<T: BigEnumSetType> BitXor<&BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitXor<&BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
^ operator.Source§impl<T: BigEnumSetType> BitXor<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitXor<&BigEnumSet<T>> for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
^ operator.Source§impl<T: BigEnumSetType> BitXor<BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitXor<BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
^ operator.Source§impl<T: BigEnumSetType> BitXor<T> for &BigEnumSet<T>
impl<T: BigEnumSetType> BitXor<T> for &BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitXor<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitXor<T> for BigEnumSet<T>
Source§impl<T: BigEnumSetType> BitXor for BigEnumSet<T>
impl<T: BigEnumSetType> BitXor for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
^ operator.Source§impl<T: BigEnumSetType> BitXorAssign<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> BitXorAssign<&BigEnumSet<T>> for BigEnumSet<T>
Source§fn bitxor_assign(&mut self, other: &BigEnumSet<T>)
fn bitxor_assign(&mut self, other: &BigEnumSet<T>)
^= operation. Read moreSource§impl<T: BigEnumSetType> BitXorAssign<T> for BigEnumSet<T>
impl<T: BigEnumSetType> BitXorAssign<T> for BigEnumSet<T>
Source§fn bitxor_assign(&mut self, value: T)
fn bitxor_assign(&mut self, value: T)
^= operation. Read moreSource§impl<T: BigEnumSetType> BitXorAssign for BigEnumSet<T>
impl<T: BigEnumSetType> BitXorAssign for BigEnumSet<T>
Source§fn bitxor_assign(&mut self, other: BigEnumSet<T>)
fn bitxor_assign(&mut self, other: BigEnumSet<T>)
^= operation. Read moreSource§impl<T: Clone + BigEnumSetType> Clone for BigEnumSet<T>where
T::Repr: Clone,
impl<T: Clone + BigEnumSetType> Clone for BigEnumSet<T>where
T::Repr: Clone,
Source§fn clone(&self) -> BigEnumSet<T>
fn clone(&self) -> BigEnumSet<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: BigEnumSetType + Debug> Debug for BigEnumSet<T>
impl<T: BigEnumSetType + Debug> Debug for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Default for BigEnumSet<T>
impl<T: BigEnumSetType> Default for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Extend<T> for BigEnumSet<T>
impl<T: BigEnumSetType> Extend<T> for BigEnumSet<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
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: BigEnumSetType> From<T> for BigEnumSet<T>
impl<T: BigEnumSetType> From<T> for BigEnumSet<T>
Source§impl<T: BigEnumSetType> FromIterator<T> for BigEnumSet<T>
impl<T: BigEnumSetType> FromIterator<T> for BigEnumSet<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Source§impl<T: BigEnumSetType> Hash for BigEnumSet<T>
impl<T: BigEnumSetType> Hash for BigEnumSet<T>
Source§impl<T: BigEnumSetType> IntoIterator for BigEnumSet<T>
impl<T: BigEnumSetType> IntoIterator for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Not for &BigEnumSet<T>
impl<T: BigEnumSetType> Not for &BigEnumSet<T>
Source§impl<T: BigEnumSetType> Not for BigEnumSet<T>
impl<T: BigEnumSetType> Not for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Ord for BigEnumSet<T>
impl<T: BigEnumSetType> Ord for BigEnumSet<T>
Source§impl<T: BigEnumSetType> PartialEq<T> for BigEnumSet<T>
impl<T: BigEnumSetType> PartialEq<T> for BigEnumSet<T>
Source§impl<T: PartialEq + BigEnumSetType> PartialEq for BigEnumSet<T>where
T::Repr: PartialEq,
impl<T: PartialEq + BigEnumSetType> PartialEq for BigEnumSet<T>where
T::Repr: PartialEq,
Source§impl<T: BigEnumSetType> PartialOrd for BigEnumSet<T>
impl<T: BigEnumSetType> PartialOrd for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Sub<&BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> Sub<&BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
- operator.Source§impl<T: BigEnumSetType> Sub<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> Sub<&BigEnumSet<T>> for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
- operator.Source§impl<T: BigEnumSetType> Sub<BigEnumSet<T>> for &BigEnumSet<T>
impl<T: BigEnumSetType> Sub<BigEnumSet<T>> for &BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
- operator.Source§impl<T: BigEnumSetType> Sub<T> for &BigEnumSet<T>
impl<T: BigEnumSetType> Sub<T> for &BigEnumSet<T>
Source§impl<T: BigEnumSetType> Sub<T> for BigEnumSet<T>
impl<T: BigEnumSetType> Sub<T> for BigEnumSet<T>
Source§impl<T: BigEnumSetType> Sub for BigEnumSet<T>
impl<T: BigEnumSetType> Sub for BigEnumSet<T>
Source§type Output = BigEnumSet<T>
type Output = BigEnumSet<T>
- operator.Source§impl<T: BigEnumSetType> SubAssign<&BigEnumSet<T>> for BigEnumSet<T>
impl<T: BigEnumSetType> SubAssign<&BigEnumSet<T>> for BigEnumSet<T>
Source§fn sub_assign(&mut self, other: &BigEnumSet<T>)
fn sub_assign(&mut self, other: &BigEnumSet<T>)
-= operation. Read moreSource§impl<T: BigEnumSetType> SubAssign<T> for BigEnumSet<T>
impl<T: BigEnumSetType> SubAssign<T> for BigEnumSet<T>
Source§fn sub_assign(&mut self, value: T)
fn sub_assign(&mut self, value: T)
-= operation. Read moreSource§impl<T: BigEnumSetType> SubAssign for BigEnumSet<T>
impl<T: BigEnumSetType> SubAssign for BigEnumSet<T>
Source§fn sub_assign(&mut self, other: BigEnumSet<T>)
fn sub_assign(&mut self, other: BigEnumSet<T>)
-= operation. Read more