pub struct ProgrammerStateSet { /* private fields */ }
Expand description
A set of ProgrammerState
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 ProgrammerStateSet
is exactly the same of a u16
.
This is true regardless of any #[repr(..)]
attribute set on ProgrammerState
.
§Invariant
Only the last 9 (the number of variants in ProgrammerState
) 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 ProgrammerStateSet
impl ProgrammerStateSet
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty ProgrammerStateSet
.
Sourcepub fn from<T: IntoIterator<Item = I>, I: Borrow<ProgrammerState>>(
iter: T,
) -> Self
pub fn from<T: IntoIterator<Item = I>, I: Borrow<ProgrammerState>>( iter: T, ) -> Self
Creates a new ProgrammerStateSet
from an iterator that yields any borrowed type of
ProgrammerState
variants. Duplicated values are ignored.
Sourcepub const fn from_slice(slice: &[ProgrammerState]) -> Self
pub const fn from_slice(slice: &[ProgrammerState]) -> Self
Creates a new ProgrammerStateSet
from a slice of the variants of the set. Can be used in
const contexts.
Sourcepub const fn from_array<const N: usize>(array: [ProgrammerState; N]) -> Self
pub const fn from_array<const N: usize>(array: [ProgrammerState; N]) -> Self
Creates a new ProgrammerStateSet
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 ProgrammerStateSet
.
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Creates a new ProgrammerStateSet
that contains all the variants of ProgrammerState
.
Sourcepub const fn is_all(&self) -> bool
pub const fn is_all(&self) -> bool
Returns true
if the set contains all 9 possible variants of ProgrammerState
.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of variants of ProgrammerState
present in the set.
Sourcepub fn contains<T: Borrow<ProgrammerState>>(&self, item: T) -> bool
pub fn contains<T: Borrow<ProgrammerState>>(&self, item: T) -> bool
Returns true
if the set contains the given variant. The variant can be specified by
any borrow of ProgrammerState
.
Sourcepub fn contains_const(&self, item: &ProgrammerState) -> bool
pub fn contains_const(&self, item: &ProgrammerState) -> bool
Returns true
if the set contains the given variant. This version of
contains
can be used in const contexts, but does
not allow using a borrowed type of ProgrammerState
.
Sourcepub const fn union(&self, other: &Self) -> Self
pub const fn union(&self, other: &Self) -> Self
Creates a new ProgrammerStateSet
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 ProgrammerStateSet
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 ProgrammerStateSet
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 ProgrammerStateSet
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 ProgrammerStateSet
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<ProgrammerState>>(&mut self, item: T)
pub fn insert<T: Borrow<ProgrammerState>>(&mut self, item: T)
Inserts a variant into the set. The variant can be specified by any borrow of ProgrammerState
.
Sourcepub fn remove<T: Borrow<ProgrammerState>>(&mut self, item: T)
pub fn remove<T: Borrow<ProgrammerState>>(&mut self, item: T)
Removes a variant from the set. The variant can be specified by any borrow of ProgrammerState
.
Sourcepub const fn insert_const(&mut self, item: &ProgrammerState)
pub const fn insert_const(&mut self, item: &ProgrammerState)
Inserts a variant into the set. This version of insert
can be
used in const contexts, but does not allow using a borrowed type of ProgrammerState
.
Sourcepub const fn remove_const(&mut self, item: &ProgrammerState)
pub const fn remove_const(&mut self, item: &ProgrammerState)
Removes a variant from the set. This version of remove
can be used in
const contexts, but does not allow using a borrowed type of ProgrammerState
.
Sourcepub const fn iter(&self) -> ProgrammerStateSetSetIter ⓘ
pub const fn iter(&self) -> ProgrammerStateSetSetIter ⓘ
Returns an iterator over the variants of ProgrammerState
contained in the set. Variants are
yielded in the order in which they appear in the definition of ProgrammerState
, regardless
of insertion order.
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
ProgrammerState
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 ProgrammerStateSet
from an integer interpreted as a bitset. The N-th variant
of ProgrammerState
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 ProgrammerState
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 ProgrammerStateSet
.
Sourcepub const unsafe fn from_repr_unchecked(repr: u16) -> Self
pub const unsafe fn from_repr_unchecked(repr: u16) -> Self
Creates a new ProgrammerStateSet
from an integer interpreted as a bitset. The N-th variant
of ProgrammerState
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 ProgrammerState
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 ProgrammerStateSet
from an integer interpreted as a bitset, silently discarding invalid bits.
The N-th variant of ProgrammerState
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 ProgrammerStateSet
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 ProgrammerState
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<ProgrammerState>>(&self) -> B
pub fn collect<B: FromIterator<ProgrammerState>>(&self) -> B
Collects the values present in the set into any value that can be formed by an iterator of ProgrammerState
.
That is, any value that implements FromIterator<
ProgrammerState`>.
Trait Implementations§
Source§impl Add<&ProgrammerState> for ProgrammerStateSet
impl Add<&ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
+
operator.Source§fn add(self, rhs: &ProgrammerState) -> Self
fn add(self, rhs: &ProgrammerState) -> Self
+
operation. Read moreSource§impl Add<&ProgrammerStateSet> for ProgrammerStateSet
impl Add<&ProgrammerStateSet> for ProgrammerStateSet
Source§impl Add<ProgrammerState> for ProgrammerStateSet
impl Add<ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
+
operator.Source§fn add(self, rhs: ProgrammerState) -> Self
fn add(self, rhs: ProgrammerState) -> Self
+
operation. Read moreSource§impl Add for ProgrammerStateSet
impl Add for ProgrammerStateSet
Source§impl AddAssign<&ProgrammerState> for ProgrammerStateSet
impl AddAssign<&ProgrammerState> for ProgrammerStateSet
Source§fn add_assign(&mut self, rhs: &ProgrammerState)
fn add_assign(&mut self, rhs: &ProgrammerState)
+=
operation. Read moreSource§impl AddAssign<&ProgrammerStateSet> for ProgrammerStateSet
impl AddAssign<&ProgrammerStateSet> for ProgrammerStateSet
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+=
operation. Read moreSource§impl AddAssign<ProgrammerState> for ProgrammerStateSet
impl AddAssign<ProgrammerState> for ProgrammerStateSet
Source§fn add_assign(&mut self, rhs: ProgrammerState)
fn add_assign(&mut self, rhs: ProgrammerState)
+=
operation. Read moreSource§impl AddAssign for ProgrammerStateSet
impl AddAssign for ProgrammerStateSet
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl BitAnd<&ProgrammerStateSet> for ProgrammerStateSet
impl BitAnd<&ProgrammerStateSet> for ProgrammerStateSet
Source§impl BitAnd for ProgrammerStateSet
impl BitAnd for ProgrammerStateSet
Source§impl BitAndAssign<&ProgrammerStateSet> for ProgrammerStateSet
impl BitAndAssign<&ProgrammerStateSet> for ProgrammerStateSet
Source§fn bitand_assign(&mut self, rhs: &Self)
fn bitand_assign(&mut self, rhs: &Self)
&=
operation. Read moreSource§impl BitAndAssign for ProgrammerStateSet
impl BitAndAssign for ProgrammerStateSet
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl BitOr<&ProgrammerState> for ProgrammerStateSet
impl BitOr<&ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
|
operator.Source§fn bitor(self, rhs: &ProgrammerState) -> Self
fn bitor(self, rhs: &ProgrammerState) -> Self
|
operation. Read moreSource§impl BitOr<&ProgrammerStateSet> for ProgrammerStateSet
impl BitOr<&ProgrammerStateSet> for ProgrammerStateSet
Source§impl BitOr<ProgrammerState> for ProgrammerStateSet
impl BitOr<ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
|
operator.Source§fn bitor(self, rhs: ProgrammerState) -> Self
fn bitor(self, rhs: ProgrammerState) -> Self
|
operation. Read moreSource§impl BitOr for ProgrammerStateSet
impl BitOr for ProgrammerStateSet
Source§impl BitOrAssign<&ProgrammerStateSet> for ProgrammerStateSet
impl BitOrAssign<&ProgrammerStateSet> for ProgrammerStateSet
Source§fn bitor_assign(&mut self, rhs: &Self)
fn bitor_assign(&mut self, rhs: &Self)
|=
operation. Read moreSource§impl BitOrAssign for ProgrammerStateSet
impl BitOrAssign for ProgrammerStateSet
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moreSource§impl BitXor<&ProgrammerStateSet> for ProgrammerStateSet
impl BitXor<&ProgrammerStateSet> for ProgrammerStateSet
Source§impl BitXor for ProgrammerStateSet
impl BitXor for ProgrammerStateSet
Source§impl BitXorAssign<&ProgrammerStateSet> for ProgrammerStateSet
impl BitXorAssign<&ProgrammerStateSet> for ProgrammerStateSet
Source§fn bitxor_assign(&mut self, rhs: &Self)
fn bitxor_assign(&mut self, rhs: &Self)
^=
operation. Read moreSource§impl BitXorAssign for ProgrammerStateSet
impl BitXorAssign for ProgrammerStateSet
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moreSource§impl Clone for ProgrammerStateSet
impl Clone for ProgrammerStateSet
Source§fn clone(&self) -> ProgrammerStateSet
fn clone(&self) -> ProgrammerStateSet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ProgrammerStateSet
impl Debug for ProgrammerStateSet
Source§impl Default for ProgrammerStateSet
impl Default for ProgrammerStateSet
Source§impl<'a> Extend<&'a ProgrammerState> for ProgrammerStateSet
impl<'a> Extend<&'a ProgrammerState> for ProgrammerStateSet
Source§fn extend<T: IntoIterator<Item = &'a ProgrammerState>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a ProgrammerState>>(&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<ProgrammerState> for ProgrammerStateSet
impl Extend<ProgrammerState> for ProgrammerStateSet
Source§fn extend<T: IntoIterator<Item = ProgrammerState>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = ProgrammerState>>(&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<&ProgrammerState> for ProgrammerStateSet
impl From<&ProgrammerState> for ProgrammerStateSet
Source§fn from(item: &ProgrammerState) -> Self
fn from(item: &ProgrammerState) -> Self
Source§impl From<ProgrammerState> for ProgrammerStateSet
impl From<ProgrammerState> for ProgrammerStateSet
Source§fn from(item: ProgrammerState) -> Self
fn from(item: ProgrammerState) -> Self
Source§impl<'a> FromIterator<&'a ProgrammerState> for ProgrammerStateSet
impl<'a> FromIterator<&'a ProgrammerState> for ProgrammerStateSet
Source§fn from_iter<T: IntoIterator<Item = &'a ProgrammerState>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = &'a ProgrammerState>>(iter: T) -> Self
Source§impl FromIterator<ProgrammerState> for ProgrammerStateSet
impl FromIterator<ProgrammerState> for ProgrammerStateSet
Source§fn from_iter<T: IntoIterator<Item = ProgrammerState>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = ProgrammerState>>(iter: T) -> Self
Source§impl Hash for ProgrammerStateSet
impl Hash for ProgrammerStateSet
Source§impl IntoIterator for ProgrammerStateSet
impl IntoIterator for ProgrammerStateSet
Source§impl Not for ProgrammerStateSet
impl Not for ProgrammerStateSet
Source§impl Ord for ProgrammerStateSet
impl Ord for ProgrammerStateSet
Source§fn cmp(&self, other: &ProgrammerStateSet) -> Ordering
fn cmp(&self, other: &ProgrammerStateSet) -> 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 ProgrammerStateSet
impl PartialEq for ProgrammerStateSet
Source§impl PartialOrd for ProgrammerStateSet
impl PartialOrd for ProgrammerStateSet
Source§impl Sub<&ProgrammerState> for ProgrammerStateSet
impl Sub<&ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
-
operator.Source§fn sub(self, rhs: &ProgrammerState) -> Self
fn sub(self, rhs: &ProgrammerState) -> Self
-
operation. Read moreSource§impl Sub<&ProgrammerStateSet> for ProgrammerStateSet
impl Sub<&ProgrammerStateSet> for ProgrammerStateSet
Source§impl Sub<ProgrammerState> for ProgrammerStateSet
impl Sub<ProgrammerState> for ProgrammerStateSet
Source§type Output = ProgrammerStateSet
type Output = ProgrammerStateSet
-
operator.Source§fn sub(self, rhs: ProgrammerState) -> Self
fn sub(self, rhs: ProgrammerState) -> Self
-
operation. Read moreSource§impl Sub for ProgrammerStateSet
impl Sub for ProgrammerStateSet
Source§impl SubAssign<&ProgrammerState> for ProgrammerStateSet
impl SubAssign<&ProgrammerState> for ProgrammerStateSet
Source§fn sub_assign(&mut self, rhs: &ProgrammerState)
fn sub_assign(&mut self, rhs: &ProgrammerState)
-=
operation. Read moreSource§impl SubAssign<&ProgrammerStateSet> for ProgrammerStateSet
impl SubAssign<&ProgrammerStateSet> for ProgrammerStateSet
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-=
operation. Read moreSource§impl SubAssign<ProgrammerState> for ProgrammerStateSet
impl SubAssign<ProgrammerState> for ProgrammerStateSet
Source§fn sub_assign(&mut self, rhs: ProgrammerState)
fn sub_assign(&mut self, rhs: ProgrammerState)
-=
operation. Read moreSource§impl SubAssign for ProgrammerStateSet
impl SubAssign for ProgrammerStateSet
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more