Skip to main content

MixedEnumSet

Struct MixedEnumSet 

Source
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>

Source

pub const fn new() -> Self

Creates an empty MixedEnumSet.

Source

pub const fn empty() -> Self

Creates an empty MixedEnumSet.

This is an alias for MixedEnumSet::new.

Source

pub const fn all() -> Self

Returns a MixedEnumSet containing all valid variants of the enum.

Source

pub const fn variant_count() -> u32

The number of valid variants that this type can contain.

Source

pub fn only(t: T) -> Self

Returns a set containing a single element.

Source

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.

Source

pub fn is_bit_valid(bit: u32) -> bool

Returns whether a given bit is valid for this set.

Source

pub fn len(&self) -> usize

Returns the number of elements in this set.

Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

Source

pub fn clear(&mut self)

Removes all elements from the set.

Source

pub fn contains(&self, value: T) -> bool

Checks whether this set contains a value.

Source

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.

Source

pub fn remove(&mut self, value: T) -> bool

Removes a value from this set. Returns whether the value was present in the set.

Source

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.

Source

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.

Source

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.

Source

pub fn union(&self, other: impl Into<Self>) -> Self

Returns a set containing any elements present in either set.

Source

pub fn intersection(&self, other: impl Into<Self>) -> Self

Returns a set containing every element present in both sets.

Source

pub fn difference(&self, other: impl Into<Self>) -> Self

Returns a set containing every element present in self but not in other.

Source

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.

Source

pub fn symmetrical_difference(&self, other: impl Into<Self>) -> Self

👎Deprecated since 1.1.13:

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.

Source

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.

Source

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.

Source

pub fn valid_len(&self) -> usize

Returns the number of elements in this set, excluding unknown bits.

Source

pub fn has_unknown_bits(&self) -> bool

Returns whether this bitset contains any bits that do not correspond to a valid variant.

Source

pub fn has_bit(&self, value: u32) -> bool

Checks whether this set contains a specific bit.

Source

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.

Source

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.

Source

pub fn insert_all(&mut self, other: impl Into<Self>)

Adds all elements in another set to this one.

Source

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>

Source

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.

Source

pub fn from_repr(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self

Constructs a bitset from a T::Repr.

Source

pub fn from_repr_truncated(bits: <T as EnumSetTypeWithRepr>::Repr) -> Self

Constructs a bitset from a T::Repr, ignoring invalid variants.

Source

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.

Source

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.

Source

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>

Source

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>

Source§

type Output = MixedEnumSet<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: O) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitAndAssign<O> for MixedEnumSet<T>

Source§

fn bitand_assign(&mut self, rhs: O)

Performs the &= operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOr<O> for MixedEnumSet<T>

Source§

type Output = MixedEnumSet<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: O) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitOrAssign<O> for MixedEnumSet<T>

Source§

fn bitor_assign(&mut self, rhs: O)

Performs the |= operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXor<O> for MixedEnumSet<T>

Source§

type Output = MixedEnumSet<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: O) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> BitXorAssign<O> for MixedEnumSet<T>

Source§

fn bitxor_assign(&mut self, rhs: O)

Performs the ^= operation. Read more
Source§

impl<T: Clone + EnumSetTypeWithRepr> Clone for MixedEnumSet<T>

Source§

fn clone(&self) -> MixedEnumSet<T>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Copy + EnumSetTypeWithRepr> Copy for MixedEnumSet<T>

Source§

impl<T: EnumSetTypeWithRepr + Debug> Debug for MixedEnumSet<T>

Source§

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

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

impl<T: EnumSetTypeWithRepr> Default for MixedEnumSet<T>

Source§

fn default() -> Self

Returns an empty set.

Source§

impl<T: EnumSetTypeWithRepr + Display> Display for MixedEnumSet<T>

Source§

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

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

impl<T: Eq + EnumSetTypeWithRepr> Eq for MixedEnumSet<T>

Source§

impl<'a, T: EnumSetTypeWithRepr> Extend<&'a EnumSet<T>> for MixedEnumSet<T>

Source§

fn extend<I: IntoIterator<Item = &'a EnumSet<T>>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<'a, T: EnumSetTypeWithRepr> Extend<&'a MixedEnumSet<T>> for MixedEnumSet<T>

Source§

fn extend<I: IntoIterator<Item = &'a MixedEnumSet<T>>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<'a, T: EnumSetTypeWithRepr> Extend<&'a T> for MixedEnumSet<T>

Source§

fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<T: EnumSetTypeWithRepr> Extend<EnumSet<T>> for MixedEnumSet<T>

Source§

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

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<T: EnumSetTypeWithRepr> Extend<MixedEnumSet<T>> for MixedEnumSet<T>

Source§

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

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<T: EnumSetTypeWithRepr> Extend<T> for MixedEnumSet<T>

Source§

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

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

fn extend_one(&mut self, item: A)

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

fn extend_reserve(&mut self, additional: usize)

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

impl<T: EnumSetTypeWithRepr> From<EnumSet<T>> for MixedEnumSet<T>

Source§

fn from(value: EnumSet<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: EnumSetTypeWithRepr> From<T> for MixedEnumSet<T>

Source§

fn from(t: T) -> Self

Converts to this type from the input type.
Source§

impl<T: EnumSetTypeWithRepr, const N: usize> From<[T; N]> for MixedEnumSet<T>

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a EnumSet<T>> for MixedEnumSet<T>

Source§

fn from_iter<I: IntoIterator<Item = &'a EnumSet<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a, T: 'a + EnumSetTypeWithRepr> FromIterator<&'a T> for MixedEnumSet<T>

Source§

fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: EnumSetTypeWithRepr> FromIterator<EnumSet<T>> for MixedEnumSet<T>

Source§

fn from_iter<I: IntoIterator<Item = EnumSet<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: EnumSetTypeWithRepr> FromIterator<MixedEnumSet<T>> for MixedEnumSet<T>

Source§

fn from_iter<I: IntoIterator<Item = MixedEnumSet<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: EnumSetTypeWithRepr> FromIterator<T> for MixedEnumSet<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: EnumSetTypeWithRepr> Hash for MixedEnumSet<T>

Source§

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

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

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

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

impl<T: EnumSetTypeWithRepr> IntoIterator for MixedEnumSet<T>

Source§

type Item = MixedValue<T>

The type of the elements being iterated over.
Source§

type IntoIter = MixedEnumSetIter<T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: EnumSetTypeWithRepr> Not for MixedEnumSet<T>

Source§

type Output = MixedEnumSet<T>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<T: EnumSetTypeWithRepr> Ord for MixedEnumSet<T>

Source§

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

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

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

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

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

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

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

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

impl<T: PartialEq + EnumSetTypeWithRepr> PartialEq for MixedEnumSet<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: EnumSetTypeWithRepr> PartialEq<EnumSet<T>> for MixedEnumSet<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: EnumSetTypeWithRepr> PartialEq<MixedEnumSet<T>> for EnumSet<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: EnumSetTypeWithRepr> PartialEq<T> for MixedEnumSet<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: EnumSetTypeWithRepr> PartialOrd for MixedEnumSet<T>

Source§

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

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

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

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

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

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

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

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

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

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

impl<T: PartialEq + EnumSetTypeWithRepr> StructuralPartialEq for MixedEnumSet<T>

Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> Sub<O> for MixedEnumSet<T>

Source§

type Output = MixedEnumSet<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: O) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: EnumSetTypeWithRepr, O: Into<MixedEnumSet<T>>> SubAssign<O> for MixedEnumSet<T>

Source§

fn sub_assign(&mut self, rhs: O)

Performs the -= operation. Read more
Source§

impl<T: EnumSetTypeWithRepr> Sum for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, T: EnumSetTypeWithRepr> Sum<&'a EnumSet<T>> for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = &'a EnumSet<T>>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, T: EnumSetTypeWithRepr> Sum<&'a MixedEnumSet<T>> for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, T: EnumSetTypeWithRepr> Sum<&'a T> for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = &'a T>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, T: EnumSetTypeWithRepr> Sum<EnumSet<T>> for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = EnumSet<T>>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: EnumSetTypeWithRepr> Sum<T> for MixedEnumSet<T>

Source§

fn sum<I: Iterator<Item = T>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.