pub struct MixedEnumSet<T: EnumSetTypeWithRepr> { /* private fields */ }Expand description
A variant of EnumSet that preserves unknown bits.
It only works for enums with an
#[enumset(repr = "…")] attribute used
with a primitive integer type.
§Numeric Representation
MixedEnumSet uses the same underlying
numeric representation as EnumSet. However, bits that do
not correspond to an enum variant can be set.
§Serialization
When the serde feature is enabled, MixedEnumSets can be serialized and deserialized using
the serde crate. It is always serialized as a single integer of the underlying repr type.
Unlike EnumSet, it ignores all flags given to EnumSetType.
§FFI Safety
MixedEnumSet may be used interchangeably with the specified repr type in FFI.
Implementations§
Source§impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Creates an empty MixedEnumSet.
This is an alias for MixedEnumSet::new.
Sourcepub const fn variant_count() -> u32
pub const fn variant_count() -> u32
The number of valid variants that this type can contain.
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 n + 1th least significant bit
of the underlying integer, corresponding to a mask of 1 << n.
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<Self>) -> bool
pub fn is_disjoint(&self, other: impl Into<Self>) -> 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<Self>) -> bool
pub fn is_superset(&self, other: impl Into<Self>) -> 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<Self>) -> bool
pub fn is_subset(&self, other: impl Into<Self>) -> 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<Self>) -> Self
pub fn union(&self, other: impl Into<Self>) -> Self
Returns a set containing any elements present in either set.
Sourcepub fn intersection(&self, other: impl Into<Self>) -> Self
pub fn intersection(&self, other: impl Into<Self>) -> Self
Returns a set containing every element present in both sets.
Sourcepub fn difference(&self, other: impl Into<Self>) -> Self
pub fn difference(&self, other: impl Into<Self>) -> Self
Returns a set containing every element present in self but not in other.
Sourcepub fn symmetric_difference(&self, other: impl Into<Self>) -> Self
pub fn symmetric_difference(&self, other: impl Into<Self>) -> Self
Returns a set containing every element present in either self or other, but not
present in both.
Sourcepub fn symmetrical_difference(&self, other: impl Into<Self>) -> Self
👎Deprecated since 1.1.13: use symmetric_difference instead
pub fn symmetrical_difference(&self, other: impl Into<Self>) -> Self
use symmetric_difference instead
Returns a set containing every element present in either self or other, but not
present in both.
This is a legacy name for this function, and should not be used.
Sourcepub fn complement(&self) -> Self
pub fn complement(&self) -> Self
Returns a set containing all enum variants not in this set.
This method clears any unknown bits already existing in the set.
Sourcepub fn full_complement(&self) -> Self
pub fn full_complement(&self) -> Self
Returns a set containing all bits not in this set.
This method sets any unknown bits not already existing in the set.
Sourcepub fn valid_len(&self) -> usize
pub fn valid_len(&self) -> usize
Returns the number of elements in this set, excluding unknown bits.
Sourcepub fn has_unknown_bits(&self) -> bool
pub fn has_unknown_bits(&self) -> bool
Returns whether this bitset contains any bits that do not correspond to a valid variant.
Sourcepub fn insert_bit(&mut self, value: u32) -> bool
pub fn insert_bit(&mut self, value: u32) -> bool
Adds a specific bit to this set.
If the set did not have this bit present, true is returned.
If the set did have this bit present, false is returned.
Sourcepub fn remove_bit(&mut self, value: u32) -> bool
pub fn remove_bit(&mut self, value: u32) -> bool
Removes a specific bit from this set. Returns whether the bit was present in the set.
Sourcepub fn insert_all(&mut self, other: impl Into<Self>)
pub fn insert_all(&mut self, other: impl Into<Self>)
Adds all elements in another set to this one.
Sourcepub fn remove_all(&mut self, other: impl Into<Self>)
pub fn remove_all(&mut self, other: impl Into<Self>)
Removes all values in another set from this one.
Source§impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
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.
Sourcepub fn from_repr(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self
pub fn from_repr(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self
Constructs a bitset from a T::Repr.
Sourcepub fn from_repr_truncated(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self
pub fn from_repr_truncated(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self
Constructs a bitset from a T::Repr, ignoring invalid variants.
Sourcepub fn as_enumset(&self) -> EnumSet<T>
pub fn as_enumset(&self) -> EnumSet<T>
Converts this set into the corresponding EnumSet.
If any unknown bits are present in the set, this method will panic.
Sourcepub fn try_as_enumset(&self) -> Option<EnumSet<T>>
pub fn try_as_enumset(&self) -> Option<EnumSet<T>>
Attempts to convert this set into the corresponding EnumSet.
If any unknown bits are present in the set, this method will return None.
Sourcepub fn as_enumset_truncate(&self) -> EnumSet<T>
pub fn as_enumset_truncate(&self) -> EnumSet<T>
Converts this set into the corresponding EnumSet, ignoring bits that do not correspond
to a variant.
Source§impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> MixedEnumSet<T>
Sourcepub fn iter(&self) -> MixedEnumSetIter<T> ⓘ
pub fn iter(&self) -> MixedEnumSetIter<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: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitAnd<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitAnd<O> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitAndAssign<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitAndAssign<O> for MixedEnumSet<T>
Source§fn bitand_assign(&mut self, rhs: O)
fn bitand_assign(&mut self, rhs: O)
&= operation. Read moreSource§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOr<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOr<O> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOrAssign<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOrAssign<O> for MixedEnumSet<T>
Source§fn bitor_assign(&mut self, rhs: O)
fn bitor_assign(&mut self, rhs: O)
|= operation. Read moreSource§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXor<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXor<O> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXorAssign<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXorAssign<O> for MixedEnumSet<T>
Source§fn bitxor_assign(&mut self, rhs: O)
fn bitxor_assign(&mut self, rhs: O)
^= operation. Read moreSource§impl<T: Clone + EnumSetTypeWithRepr> Clone for MixedEnumSet<T>
impl<T: Clone + EnumSetTypeWithRepr> Clone for MixedEnumSet<T>
Source§fn clone(&self) -> MixedEnumSet<T>
fn clone(&self) -> MixedEnumSet<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T: Copy + EnumSetTypeWithRepr> Copy for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr + Debug> Debug for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr + Debug> Debug for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> Default for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Default for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr + Display> Display for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr + Display> Display for MixedEnumSet<T>
impl<T: Eq + EnumSetTypeWithRepr> Eq for MixedEnumSet<T>
Source§impl<'a, T: EnumSetTypeWithRepr> Extend<&'a EnumSet<T>> for MixedEnumSet<T>
impl<'a, T: EnumSetTypeWithRepr> Extend<&'a EnumSet<T>> for MixedEnumSet<T>
Source§fn extend<I: IntoIterator<Item = &'a EnumSet<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a EnumSet<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<'a, T: EnumSetTypeWithRepr> Extend<&'a MixedEnumSet<T>> for MixedEnumSet<T>
impl<'a, T: EnumSetTypeWithRepr> Extend<&'a MixedEnumSet<T>> for MixedEnumSet<T>
Source§fn extend<I: IntoIterator<Item = &'a MixedEnumSet<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a MixedEnumSet<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<'a, T: EnumSetTypeWithRepr> Extend<&'a T> for MixedEnumSet<T>
impl<'a, T: EnumSetTypeWithRepr> Extend<&'a T> for MixedEnumSet<T>
Source§fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a 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: EnumSetTypeWithRepr> Extend<EnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Extend<EnumSet<T>> for MixedEnumSet<T>
Source§fn extend<I: IntoIterator<Item = EnumSet<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = EnumSet<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: EnumSetTypeWithRepr> Extend<MixedEnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Extend<MixedEnumSet<T>> for MixedEnumSet<T>
Source§fn extend<I: IntoIterator<Item = MixedEnumSet<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = MixedEnumSet<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: EnumSetTypeWithRepr> Extend<T> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Extend<T> for MixedEnumSet<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: EnumSetTypeWithRepr> From<EnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> From<EnumSet<T>> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> From<T> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> From<T> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, const N: usize> From<[T; N]> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, const N: usize> From<[T; N]> for MixedEnumSet<T>
Source§impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a EnumSet<T>> for MixedEnumSet<T>
impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a EnumSet<T>> for MixedEnumSet<T>
Source§impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a MixedEnumSet<T>> for MixedEnumSet<T>
impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a MixedEnumSet<T>> for MixedEnumSet<T>
Source§fn from_iter<I: IntoIterator<Item = &'a MixedEnumSet<T>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = &'a MixedEnumSet<T>>>(iter: I) -> Self
Source§impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a T> for MixedEnumSet<T>
impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a T> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> FromIterator<EnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> FromIterator<EnumSet<T>> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> FromIterator<MixedEnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> FromIterator<MixedEnumSet<T>> for MixedEnumSet<T>
Source§fn from_iter<I: IntoIterator<Item = MixedEnumSet<T>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = MixedEnumSet<T>>>(iter: I) -> Self
Source§impl<T: EnumSetTypeWithRepr> FromIterator<T> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> FromIterator<T> for MixedEnumSet<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: EnumSetTypeWithRepr> Hash for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Hash for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> IntoIterator for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> IntoIterator for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> Not for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Not for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> Ord for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> Ord for MixedEnumSet<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq + EnumSetTypeWithRepr> PartialEq for MixedEnumSet<T>
impl<T: PartialEq + EnumSetTypeWithRepr> PartialEq for MixedEnumSet<T>
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: EnumSetTypeWithRepr> PartialEq<EnumSet<T>> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> PartialEq<EnumSet<T>> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> PartialEq<MixedEnumSet<T>> for EnumSet<T>
impl<T: EnumSetTypeWithRepr> PartialEq<MixedEnumSet<T>> for EnumSet<T>
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: EnumSetTypeWithRepr> PartialEq<T> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> PartialEq<T> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr> PartialOrd for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr> PartialOrd for MixedEnumSet<T>
impl<T: PartialEq + EnumSetTypeWithRepr> StructuralPartialEq for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> Sub<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> Sub<O> for MixedEnumSet<T>
Source§impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> SubAssign<O> for MixedEnumSet<T>
impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> SubAssign<O> for MixedEnumSet<T>
Source§fn sub_assign(&mut self, rhs: O)
fn sub_assign(&mut self, rhs: O)
-= operation. Read more