pub struct IntDegreeSet { /* private fields */ }Expand description
A set of IntDegree values, efficiently implemented as a bitfield.
It is internally implemented as a single u16 integer value.
The N-th least significant bit of the value is set to 1 if the N-th variant is present in the set, and 0 otherwise.
§Representation
It is guaranteed that the layout and ABI of a IntDegreeSet is exactly the same of a u16.
This is true regardless of any #[repr(..)] attribute set on IntDegree.
§Invariant
Only the last 10 (the number of variants in IntDegree) may be non-zero.
That is, the value of bits that do not correspond to an existing variant must always be set to 0.
All the intrinsic methods will respect this invariant, but please take this into account when manipulating
the state of the set via unsafe or using it in FFI.
Implementations§
Source§impl IntDegreeSet
impl IntDegreeSet
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty IntDegreeSet.
Sourcepub fn from<T: IntoIterator<Item = I>, I: Borrow<IntDegree>>(iter: T) -> Self
pub fn from<T: IntoIterator<Item = I>, I: Borrow<IntDegree>>(iter: T) -> Self
Creates a new IntDegreeSet from an iterator that yields any borrowed type of
IntDegree variants. Duplicated values are ignored.
Sourcepub const fn from_slice(slice: &[IntDegree]) -> Self
pub const fn from_slice(slice: &[IntDegree]) -> Self
Creates a new IntDegreeSet from a slice of the variants of the set. Can be used in
const contexts.
Sourcepub const fn from_array<const N: usize>(array: [IntDegree; N]) -> Self
pub const fn from_array<const N: usize>(array: [IntDegree; N]) -> Self
Creates a new IntDegreeSet from an array of the variants of the set. Can be used in
const contexts.
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Creates a new empty IntDegreeSet.
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Creates a new IntDegreeSet that contains all the variants of IntDegree.
Sourcepub const fn is_all(&self) -> bool
pub const fn is_all(&self) -> bool
Returns true if the set contains all 10 possible variants of IntDegree.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of variants of IntDegree present in the set.
Sourcepub fn contains<T: Borrow<IntDegree>>(&self, item: T) -> bool
pub fn contains<T: Borrow<IntDegree>>(&self, item: T) -> bool
Returns true if the set contains the given variant. The variant can be specified by
any borrow of IntDegree.
Sourcepub fn contains_const(&self, item: &IntDegree) -> bool
pub fn contains_const(&self, item: &IntDegree) -> bool
Sourcepub const fn union(&self, other: &Self) -> Self
pub const fn union(&self, other: &Self) -> Self
Creates a new IntDegreeSet that contains all the variants that are in either self
or other, leaving both input sets unchanged.
Sourcepub const fn intersection(&self, other: &Self) -> Self
pub const fn intersection(&self, other: &Self) -> Self
Creates a new IntDegreeSet that contains all the variants that are in both self
and other, leaving both input sets unchanged.
Sourcepub const fn difference(&self, other: &Self) -> Self
pub const fn difference(&self, other: &Self) -> Self
Creates a new IntDegreeSet that contains all the variants that are in self but not
in other, leaving both input sets unchanged.
Sourcepub const fn symmetric_difference(&self, other: &Self) -> Self
pub const fn symmetric_difference(&self, other: &Self) -> Self
Creates a new IntDegreeSet that contains all the variants that are in either self or
other, but not in both, leaving both input sets unchanged.
Sourcepub const fn complement(&self) -> Self
pub const fn complement(&self) -> Self
Creates a new IntDegreeSet that contains all the variants that are not in self, leaving the input set unchanged.
Sourcepub fn is_subset_of(&self, other: &Self) -> bool
pub fn is_subset_of(&self, other: &Self) -> bool
Returns true if self is a subset of other. That is, if self contains all
the items that exist in other.
Sourcepub fn is_superset_of(&self, other: &Self) -> bool
pub fn is_superset_of(&self, other: &Self) -> bool
Returns true if self is a superset of other. That is, if other contains all
the items that exist in self.
Sourcepub const fn is_disjoint(&self, other: &Self) -> bool
pub const fn is_disjoint(&self, other: &Self) -> bool
Returns true if self has no elements in common with other.
Sourcepub const fn is_complementary(&self, other: &Self) -> bool
pub const fn is_complementary(&self, other: &Self) -> bool
Returns true if self and other are complementary sets.
Two sets are complementary if their union contains all variants and their intersection is empty.
Sourcepub fn insert<T: Borrow<IntDegree>>(&mut self, item: T)
pub fn insert<T: Borrow<IntDegree>>(&mut self, item: T)
Inserts a variant into the set. The variant can be specified by any borrow of IntDegree.
Sourcepub fn remove<T: Borrow<IntDegree>>(&mut self, item: T)
pub fn remove<T: Borrow<IntDegree>>(&mut self, item: T)
Removes a variant from the set. The variant can be specified by any borrow of IntDegree.
Sourcepub const fn insert_const(&mut self, item: &IntDegree)
pub const fn insert_const(&mut self, item: &IntDegree)
Sourcepub const fn remove_const(&mut self, item: &IntDegree)
pub const fn remove_const(&mut self, item: &IntDegree)
Sourcepub const fn iter(&self) -> IntDegreeSetSetIter ⓘ
pub const fn iter(&self) -> IntDegreeSetSetIter ⓘ
Sourcepub const fn to_repr(&self) -> u16
pub const fn to_repr(&self) -> u16
Returns the integer representation of the set as a bitset. The N-th variant of
IntDegree corresponds to the N-th least significative bit of the integer.
Sourcepub const fn from_repr(repr: u16) -> Option<Self>
pub const fn from_repr(repr: u16) -> Option<Self>
Creates a new IntDegreeSet from an integer interpreted as a bitset. The N-th variant
of IntDegree corresponds to the N-th least significative bit of the integer.
Returns None if the integer is not a valid bitset representation of the set
(i.e, a bit that does not correspond to any variant of IntDegree is set to 1.).
Sourcepub const fn is_valid_repr(repr: u16) -> bool
pub const fn is_valid_repr(repr: u16) -> bool
Checks whether the provided value is a valid representation for a IntDegreeSet.
Sourcepub const unsafe fn from_repr_unchecked(repr: u16) -> Self
pub const unsafe fn from_repr_unchecked(repr: u16) -> Self
Creates a new IntDegreeSet from an integer interpreted as a bitset. The N-th variant
of IntDegree corresponds to the N-th least significative bit of the integer.
§Safety
The integer must be a valid bitset representation of the set, but the invariant that
bits that do not correspond to a variant of IntDegree is not checked, so must be
guaranteed by the calling code.
It is undefined behavior to pass an invalid value. Methods and iterators obtained from the generated set might exhibit incorrect behavior, including possible panics.
§Safe alternatives
Note the from_repr_masked method that silently
discards invalid bits at the cost of a (cheap) single bit-wise and operation.
Also the from_repr_discarded method that
returns the discarded bits alongide the new set instance (where those bits are
safely masked out). This can be useful as an error hanlding mechanism.
Sourcepub const unsafe fn from_repr_masked(repr: u16) -> Self
pub const unsafe fn from_repr_masked(repr: u16) -> Self
Creates a new IntDegreeSet from an integer interpreted as a bitset, silently discarding invalid bits.
The N-th variant of IntDegree corresponds to the N-th least significative bit of the integer.
If the provided repr has bits that do not map to a variant of the original enum
set to one, they are masked out and ignored to uphold the bitset integrity
invariant.
Sourcepub const unsafe fn from_repr_discarded(repr: u16) -> (Self, u16)
pub const unsafe fn from_repr_discarded(repr: u16) -> (Self, u16)
Creates a new IntDegreeSet from an integer interpreted as a bitset, discarding invalid bits.
Returns the created set and an integer where only the discarded bits are set to 1.
The N-th variant of IntDegree corresponds to the N-th least significative bit of the integer.
If the provided repr has bits that do not map to a variant of the original enum
set to one, they are masked out to uphold the bitset integrity invariant.
The discarded bits that were set are returned as the second member of the tuple.
Sourcepub fn collect<B: FromIterator<IntDegree>>(&self) -> B
pub fn collect<B: FromIterator<IntDegree>>(&self) -> B
Collects the values present in the set into any value that can be formed by an iterator of IntDegree.
That is, any value that implements FromIterator<IntDegree`>.
Trait Implementations§
Source§impl Add<&IntDegree> for IntDegreeSet
impl Add<&IntDegree> for IntDegreeSet
Source§impl Add<&IntDegreeSet> for IntDegreeSet
impl Add<&IntDegreeSet> for IntDegreeSet
Source§impl Add<IntDegree> for IntDegreeSet
impl Add<IntDegree> for IntDegreeSet
Source§impl Add for IntDegreeSet
impl Add for IntDegreeSet
Source§impl AddAssign<&IntDegree> for IntDegreeSet
impl AddAssign<&IntDegree> for IntDegreeSet
Source§fn add_assign(&mut self, rhs: &IntDegree)
fn add_assign(&mut self, rhs: &IntDegree)
+= operation. Read moreSource§impl AddAssign<&IntDegreeSet> for IntDegreeSet
impl AddAssign<&IntDegreeSet> for IntDegreeSet
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moreSource§impl AddAssign<IntDegree> for IntDegreeSet
impl AddAssign<IntDegree> for IntDegreeSet
Source§fn add_assign(&mut self, rhs: IntDegree)
fn add_assign(&mut self, rhs: IntDegree)
+= operation. Read moreSource§impl AddAssign for IntDegreeSet
impl AddAssign for IntDegreeSet
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl BitAnd<&IntDegreeSet> for IntDegreeSet
impl BitAnd<&IntDegreeSet> for IntDegreeSet
Source§impl BitAnd for IntDegreeSet
impl BitAnd for IntDegreeSet
Source§impl BitAndAssign<&IntDegreeSet> for IntDegreeSet
impl BitAndAssign<&IntDegreeSet> for IntDegreeSet
Source§fn bitand_assign(&mut self, rhs: &Self)
fn bitand_assign(&mut self, rhs: &Self)
&= operation. Read moreSource§impl BitAndAssign for IntDegreeSet
impl BitAndAssign for IntDegreeSet
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOr<&IntDegree> for IntDegreeSet
impl BitOr<&IntDegree> for IntDegreeSet
Source§impl BitOr<&IntDegreeSet> for IntDegreeSet
impl BitOr<&IntDegreeSet> for IntDegreeSet
Source§impl BitOr<IntDegree> for IntDegreeSet
impl BitOr<IntDegree> for IntDegreeSet
Source§impl BitOr for IntDegreeSet
impl BitOr for IntDegreeSet
Source§impl BitOrAssign<&IntDegreeSet> for IntDegreeSet
impl BitOrAssign<&IntDegreeSet> for IntDegreeSet
Source§fn bitor_assign(&mut self, rhs: &Self)
fn bitor_assign(&mut self, rhs: &Self)
|= operation. Read moreSource§impl BitOrAssign for IntDegreeSet
impl BitOrAssign for IntDegreeSet
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXor<&IntDegreeSet> for IntDegreeSet
impl BitXor<&IntDegreeSet> for IntDegreeSet
Source§impl BitXor for IntDegreeSet
impl BitXor for IntDegreeSet
Source§impl BitXorAssign<&IntDegreeSet> for IntDegreeSet
impl BitXorAssign<&IntDegreeSet> for IntDegreeSet
Source§fn bitxor_assign(&mut self, rhs: &Self)
fn bitxor_assign(&mut self, rhs: &Self)
^= operation. Read moreSource§impl BitXorAssign for IntDegreeSet
impl BitXorAssign for IntDegreeSet
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl Clone for IntDegreeSet
impl Clone for IntDegreeSet
Source§fn clone(&self) -> IntDegreeSet
fn clone(&self) -> IntDegreeSet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IntDegreeSet
impl Debug for IntDegreeSet
Source§impl Default for IntDegreeSet
impl Default for IntDegreeSet
Source§impl<'a> Extend<&'a IntDegree> for IntDegreeSet
impl<'a> Extend<&'a IntDegree> for IntDegreeSet
Source§fn extend<T: IntoIterator<Item = &'a IntDegree>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a IntDegree>>(&mut self, iter: 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 Extend<IntDegree> for IntDegreeSet
impl Extend<IntDegree> for IntDegreeSet
Source§fn extend<T: IntoIterator<Item = IntDegree>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = IntDegree>>(&mut self, iter: 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 From<&IntDegree> for IntDegreeSet
impl From<&IntDegree> for IntDegreeSet
Source§impl From<&IntervalSet> for IntDegreeSet
impl From<&IntervalSet> for IntDegreeSet
Source§fn from(value: &IntervalSet) -> Self
fn from(value: &IntervalSet) -> Self
Source§impl From<IntDegree> for IntDegreeSet
impl From<IntDegree> for IntDegreeSet
Source§impl<'a> FromIterator<&'a IntDegree> for IntDegreeSet
impl<'a> FromIterator<&'a IntDegree> for IntDegreeSet
Source§impl<'a> FromIterator<&'a IntDegreeSet> for IntDegreeSet
impl<'a> FromIterator<&'a IntDegreeSet> for IntDegreeSet
Source§fn from_iter<T: IntoIterator<Item = &'a IntDegreeSet>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = &'a IntDegreeSet>>(iter: T) -> Self
Source§impl FromIterator<IntDegree> for IntDegreeSet
impl FromIterator<IntDegree> for IntDegreeSet
Source§impl FromIterator<IntDegreeSet> for IntDegreeSet
impl FromIterator<IntDegreeSet> for IntDegreeSet
Source§fn from_iter<T: IntoIterator<Item = IntDegreeSet>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = IntDegreeSet>>(iter: T) -> Self
Source§impl Hash for IntDegreeSet
impl Hash for IntDegreeSet
Source§impl IntoIterator for IntDegreeSet
impl IntoIterator for IntDegreeSet
Source§impl Not for IntDegreeSet
impl Not for IntDegreeSet
Source§impl Ord for IntDegreeSet
impl Ord for IntDegreeSet
Source§fn cmp(&self, other: &IntDegreeSet) -> Ordering
fn cmp(&self, other: &IntDegreeSet) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for IntDegreeSet
impl PartialEq for IntDegreeSet
Source§impl PartialOrd for IntDegreeSet
impl PartialOrd for IntDegreeSet
Source§impl Sub<&IntDegree> for IntDegreeSet
impl Sub<&IntDegree> for IntDegreeSet
Source§impl Sub<&IntDegreeSet> for IntDegreeSet
impl Sub<&IntDegreeSet> for IntDegreeSet
Source§impl Sub<IntDegree> for IntDegreeSet
impl Sub<IntDegree> for IntDegreeSet
Source§impl Sub for IntDegreeSet
impl Sub for IntDegreeSet
Source§impl SubAssign<&IntDegree> for IntDegreeSet
impl SubAssign<&IntDegree> for IntDegreeSet
Source§fn sub_assign(&mut self, rhs: &IntDegree)
fn sub_assign(&mut self, rhs: &IntDegree)
-= operation. Read moreSource§impl SubAssign<&IntDegreeSet> for IntDegreeSet
impl SubAssign<&IntDegreeSet> for IntDegreeSet
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moreSource§impl SubAssign<IntDegree> for IntDegreeSet
impl SubAssign<IntDegree> for IntDegreeSet
Source§fn sub_assign(&mut self, rhs: IntDegree)
fn sub_assign(&mut self, rhs: IntDegree)
-= operation. Read moreSource§impl SubAssign for IntDegreeSet
impl SubAssign for IntDegreeSet
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more