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
impl PinSet
Sourcepub const fn full<const N: u8>() -> Self
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);Sourcepub const fn of<const N: usize>(pins: [u8; N]) -> Self
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));Sourcepub const fn range(start: u8, end: u8) -> Self
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]));Sourcepub const fn from_raw(bits: u16) -> Self
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.
Sourcepub const fn is_disjoint(self, other: Self) -> bool
pub const fn is_disjoint(self, other: Self) -> bool
Returns true if self and other share no common pins.
Sourcepub const fn is_subset_of(self, other: Self) -> bool
pub const fn is_subset_of(self, other: Self) -> bool
Returns true if every pin in self is also in other.
Sourcepub const fn contains_all(self, other: Self) -> bool
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).
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
Set difference: pins in self that are not in other.
Also available via the - operator.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Set intersection: pins in both self and other.
Also available via the & operator.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Set union: pins in either self or other.
Also available via the | operator.
Sourcepub const fn complement_within<const N: u8>(self) -> Self
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));Sourcepub fn iter(self) -> PinSetIter ⓘ
pub fn iter(self) -> PinSetIter ⓘ
Iterate over the pin indices present in the set.
Trait Implementations§
Source§impl BitAndAssign for PinSet
Set intersection assignment: a &= b.
impl BitAndAssign for PinSet
Set intersection assignment: a &= b.
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOrAssign for PinSet
Set union assignment: a |= b.
impl BitOrAssign for PinSet
Set union assignment: a |= b.
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreimpl Copy for PinSet
impl Eq for PinSet
Source§impl Extend<u8> for PinSet
Extend a PinSet with additional pin indices.
impl Extend<u8> for PinSet
Extend a PinSet with additional pin indices.
Source§fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)
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 FromIterator<u8> for PinSet
Collect pin indices into a PinSet.
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§impl IntoIterator for PinSet
impl IntoIterator for PinSet
Source§impl Not for PinSet
Bitwise complement: !a flips all 16 bits.
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.