Struct ProgrammerStateSet

Source
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

Source

pub const fn new() -> Self

Creates a new empty ProgrammerStateSet.

Source

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.

Source

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.

Source

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.

Source

pub const fn empty() -> Self

Creates a new empty ProgrammerStateSet.

Source

pub const fn all() -> Self

Creates a new ProgrammerStateSet that contains all the variants of ProgrammerState.

Source

pub const fn is_empty(&self) -> bool

Returns true if the set is empty.

Source

pub const fn is_all(&self) -> bool

Returns true if the set contains all 9 possible variants of ProgrammerState.

Source

pub const fn len(&self) -> usize

Returns the number of variants of ProgrammerState present in the set.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn is_disjoint(&self, other: &Self) -> bool

Returns true if self has no elements in common with other.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.).

Source

pub const fn is_valid_repr(repr: u16) -> bool

Checks whether the provided value is a valid representation for a ProgrammerStateSet.

Source

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.

Source

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.

Source

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.

Source

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

Source§

type Output = ProgrammerStateSet

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &ProgrammerState) -> Self

Performs the + operation. Read more
Source§

impl Add<&ProgrammerStateSet> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self

Performs the + operation. Read more
Source§

impl Add<ProgrammerState> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the + operator.
Source§

fn add(self, rhs: ProgrammerState) -> Self

Performs the + operation. Read more
Source§

impl Add for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<&ProgrammerState> for ProgrammerStateSet

Source§

fn add_assign(&mut self, rhs: &ProgrammerState)

Performs the += operation. Read more
Source§

impl AddAssign<&ProgrammerStateSet> for ProgrammerStateSet

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl AddAssign<ProgrammerState> for ProgrammerStateSet

Source§

fn add_assign(&mut self, rhs: ProgrammerState)

Performs the += operation. Read more
Source§

impl AddAssign for ProgrammerStateSet

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl BitAnd<&ProgrammerStateSet> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &Self) -> Self

Performs the & operation. Read more
Source§

impl BitAnd for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
Source§

impl BitAndAssign<&ProgrammerStateSet> for ProgrammerStateSet

Source§

fn bitand_assign(&mut self, rhs: &Self)

Performs the &= operation. Read more
Source§

impl BitAndAssign for ProgrammerStateSet

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr<&ProgrammerState> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &ProgrammerState) -> Self

Performs the | operation. Read more
Source§

impl BitOr<&ProgrammerStateSet> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &Self) -> Self

Performs the | operation. Read more
Source§

impl BitOr<ProgrammerState> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: ProgrammerState) -> Self

Performs the | operation. Read more
Source§

impl BitOr for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign<&ProgrammerStateSet> for ProgrammerStateSet

Source§

fn bitor_assign(&mut self, rhs: &Self)

Performs the |= operation. Read more
Source§

impl BitOrAssign for ProgrammerStateSet

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor<&ProgrammerStateSet> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &Self) -> Self

Performs the ^ operation. Read more
Source§

impl BitXor for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
Source§

impl BitXorAssign<&ProgrammerStateSet> for ProgrammerStateSet

Source§

fn bitxor_assign(&mut self, rhs: &Self)

Performs the ^= operation. Read more
Source§

impl BitXorAssign for ProgrammerStateSet

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for ProgrammerStateSet

Source§

fn clone(&self) -> ProgrammerStateSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ProgrammerStateSet

Source§

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

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

impl Default for ProgrammerStateSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Extend<&'a ProgrammerState> for ProgrammerStateSet

Source§

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

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 Extend<ProgrammerState> for ProgrammerStateSet

Source§

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

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 From<&ProgrammerState> for ProgrammerStateSet

Source§

fn from(item: &ProgrammerState) -> Self

Converts to this type from the input type.
Source§

impl From<ProgrammerState> for ProgrammerStateSet

Source§

fn from(item: ProgrammerState) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a ProgrammerState> for ProgrammerStateSet

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<ProgrammerState> for ProgrammerStateSet

Source§

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

Creates a value from an iterator. Read more
Source§

impl Hash for ProgrammerStateSet

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 IntoIterator for ProgrammerStateSet

Source§

type Item = ProgrammerState

The type of the elements being iterated over.
Source§

type IntoIter = ProgrammerStateSetSetIter

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 Not for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl Ord for ProgrammerStateSet

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for ProgrammerStateSet

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for ProgrammerStateSet

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Sub<&ProgrammerState> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &ProgrammerState) -> Self

Performs the - operation. Read more
Source§

impl Sub<&ProgrammerStateSet> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Self) -> Self

Performs the - operation. Read more
Source§

impl Sub<ProgrammerState> for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: ProgrammerState) -> Self

Performs the - operation. Read more
Source§

impl Sub for ProgrammerStateSet

Source§

type Output = ProgrammerStateSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign<&ProgrammerState> for ProgrammerStateSet

Source§

fn sub_assign(&mut self, rhs: &ProgrammerState)

Performs the -= operation. Read more
Source§

impl SubAssign<&ProgrammerStateSet> for ProgrammerStateSet

Source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
Source§

impl SubAssign<ProgrammerState> for ProgrammerStateSet

Source§

fn sub_assign(&mut self, rhs: ProgrammerState)

Performs the -= operation. Read more
Source§

impl SubAssign for ProgrammerStateSet

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Copy for ProgrammerStateSet

Source§

impl Eq for ProgrammerStateSet

Source§

impl StructuralPartialEq for ProgrammerStateSet

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.