Skip to main content

PinSet

Struct PinSet 

Source
pub struct PinSet(/* private fields */);
Expand description

A set of pins represented as a u16 bitmask (up to 16 pins).

Bit i is 1 when pin i is present in the set. The type is Copy and all operations are const-friendly where possible.

§Construction

// Infallible, const-evaluable constructors:
let ten = PinSet::full::<10>();          // first 10 pins
let specific = PinSet::of([3, 5, 6, 9]); // pins by index
let span = PinSet::range(5, 10);         // pins 5..10

// Collect from an iterator:
let collected: PinSet = (0..5).collect();

Implementations§

Source§

impl PinSet

Source

pub const EMPTY: Self

The empty set (no pins).

Source

pub const fn full<const N: u8>() -> Self

Creates a full pin set with the first N pins standing.

This is an infallible, const-evaluable constructor. The pin count is checked at compile time when used in a const context; exceeding 16 triggers a compile-time error.

let ten = PinSet::full::<10>();
assert_eq!(ten.count(), 10);
Source

pub const fn of<const N: usize>(pins: [u8; N]) -> Self

Creates a PinSet containing exactly the given pin indices.

let ps = PinSet::of([0, 1, 2]);
assert_eq!(ps.count(), 3);
assert!(ps.contains(0) && ps.contains(1) && ps.contains(2));
Source

pub const fn range(start: u8, end: u8) -> Self

Creates a PinSet with pin indices in the half-open range [start, end).

let ps = PinSet::range(3, 7);
assert_eq!(ps, PinSet::of([3, 4, 5, 6]));
Source

pub const fn from_raw(bits: u16) -> Self

Creates a PinSet from a raw bitmask. No validation; caller must ensure the mask only uses bits 0..pin_count.

Source

pub const fn to_raw(self) -> u16

Returns the underlying bitmask.

Source

pub const fn count(self) -> u8

Returns the number of pins in the set.

Source

pub const fn is_empty(self) -> bool

Returns true if the set contains no pins.

Source

pub const fn contains(self, idx: u8) -> bool

Returns true if pin idx is in the set.

Source

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

Returns true if self and other share no common pins.

Source

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

Returns true if every pin in self is also in other.

Source

pub const fn insert(self, idx: u8) -> Self

Adds a single pin to the set.

Source

pub const fn remove(self, idx: u8) -> Self

Removes a single pin from the set.

Source

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

Returns true if other is a subset of self (all bits in other are also set in self).

Source

pub const fn difference(self, other: Self) -> Self

Set difference: pins in self that are not in other.

Also available via the - operator.

Source

pub const fn intersection(self, other: Self) -> Self

Set intersection: pins in both self and other.

Also available via the & operator.

Source

pub const fn union(self, other: Self) -> Self

Set union: pins in either self or other.

Also available via the | operator.

Source

pub const fn complement_within<const N: u8>(self) -> Self

Complement within a given pin count: the pins in 0..N that are not in self.

let standing = PinSet::of([0, 1, 2]);
let knocked = standing.complement_within::<10>();
assert_eq!(knocked, PinSet::range(3, 10));
Source

pub fn iter(self) -> PinSetIter

Iterate over the pin indices present in the set.

Trait Implementations§

Source§

impl BitAnd for PinSet

Set intersection: a & b returns pins in both sets.

Source§

type Output = PinSet

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign for PinSet

Set intersection assignment: a &= b.

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for PinSet

Set union: a | b returns pins in either set.

Source§

type Output = PinSet

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign for PinSet

Set union assignment: a |= b.

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for PinSet

Source§

fn clone(&self) -> PinSet

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 Copy for PinSet

Source§

impl Debug for PinSet

Source§

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

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

impl Default for PinSet

Source§

fn default() -> PinSet

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

impl Display for PinSet

Source§

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

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

impl Eq for PinSet

Source§

impl Extend<u8> for PinSet

Extend a PinSet with additional pin indices.

Source§

fn extend<I: IntoIterator<Item = u8>>(&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 FromIterator<u8> for PinSet

Collect pin indices into a PinSet.

let ps: PinSet = [0u8, 2, 4].into_iter().collect();
assert_eq!(ps, PinSet::of([0, 2, 4]));
Source§

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

Creates a value from an iterator. Read more
Source§

impl Hash for PinSet

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 PinSet

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = PinSetIter

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 PinSet

Bitwise complement: !a flips all 16 bits.

Note: this flips all 16 bits regardless of pin count. For a complement within a specific pin count, use complement_within.

Source§

type Output = PinSet

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl PartialEq for PinSet

Source§

fn eq(&self, other: &PinSet) -> 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 StructuralPartialEq for PinSet

Source§

impl Sub for PinSet

Set difference: a - b returns pins in a that are not in b.

Source§

type Output = PinSet

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for PinSet

Set difference assignment: a -= b.

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.