Trait bit_collection::BitCollection
[−]
[src]
pub trait BitCollection: From<Self::Item> + From<BitIter<Self>> + IntoIterator<IntoIter = BitIter<Self>> + FromIterator<Self::Item> + Extend<Self::Item> + Not<Output = Self> + BitAnd<Output = Self> + BitAndAssign + BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign + Sub<Output = Self> + SubAssign { const FULL: Self; const EMPTY: Self; fn len(&self) -> usize; fn is_empty(&self) -> bool; fn has_multiple(&self) -> bool; unsafe fn lsb_unchecked(&self) -> Self::Item; unsafe fn msb_unchecked(&self) -> Self::Item; fn remove_lsb(&mut self); fn remove_msb(&mut self); fn pop_lsb(&mut self) -> Option<Self::Item>; fn pop_msb(&mut self) -> Option<Self::Item>; fn contains<T: Into<Self>>(&self, _: T) -> bool; fn quantity(&self) -> Quantity { ... } fn as_iter(&mut self) -> &mut BitIter<Self> { ... } fn into_bit(self) -> Option<Self::Item> { ... } fn lsb(&self) -> Option<Self::Item> { ... } fn msb(&self) -> Option<Self::Item> { ... } fn removing<T: Into<Self>>(self, other: T) -> Self { ... } fn inserting<T: Into<Self>>(self, other: T) -> Self { ... } fn toggling<T: Into<Self>>(self, other: T) -> Self { ... } fn intersecting<T: Into<Self>>(self, other: T) -> Self { ... } fn setting<T: Into<Self>>(self, other: T, condition: bool) -> Self { ... } fn remove<T: Into<Self>>(&mut self, other: T) -> &mut Self { ... } fn insert<T: Into<Self>>(&mut self, other: T) -> &mut Self { ... } fn toggle<T: Into<Self>>(&mut self, other: T) -> &mut Self { ... } fn intersect<T: Into<Self>>(&mut self, other: T) -> &mut Self { ... } fn set<T: Into<Self>>(&mut self, other: T, condition: bool) -> &mut Self { ... } }
A type that represents a collection of bits that can be iterated over.
Associated Constants
const FULL: Self
A full instance with all bits set.
const EMPTY: Self
An empty instance with no bits set.
Required Methods
fn len(&self) -> usize
Returns the number of bits set in self
.
If checking whether self
has zero, one, or multiple bits set, use
quantity
.
fn is_empty(&self) -> bool
Returns whether self
is empty.
fn has_multiple(&self) -> bool
Returns whether self
has multiple bits set.
unsafe fn lsb_unchecked(&self) -> Self::Item
Returns the least significant bit in self
without checking whether
self
is empty.
unsafe fn msb_unchecked(&self) -> Self::Item
Returns the most significant bit in self
without checking whether
self
is empty.
fn remove_lsb(&mut self)
Removes the least significant bit from self
.
fn remove_msb(&mut self)
Removes the most significant bit from self
.
fn pop_lsb(&mut self) -> Option<Self::Item>
Removes the least significant bit from self
and returns it.
fn pop_msb(&mut self) -> Option<Self::Item>
Removes the most significant bit from self
and returns it.
fn contains<T: Into<Self>>(&self, _: T) -> bool
Returns whether self
contains the value.
Provided Methods
fn quantity(&self) -> Quantity
Returns the quantity of bits set.
For an exact measurement of the number of bits set, use
len
.
This is much more optimal than matching len
against
0
, 1
, and _
.
fn as_iter(&mut self) -> &mut BitIter<Self>
Returns self
as an iterator over itself.
Examples
This method is useful for partially iterating over a BitCollection
in-place, and thus mutating it.
let mut rights = CastleRights::FULL; assert_eq!(rights.len(), 4); for right in rights.as_iter().take(3) { /* ... */ } assert_eq!(rights.len(), 1);
fn into_bit(self) -> Option<Self::Item>
Converts self
into the only bit set.
fn lsb(&self) -> Option<Self::Item>
Returns the least significant bit in self
if self
is not empty.
fn msb(&self) -> Option<Self::Item>
Returns the most significant bit in self
if self
is not empty.
fn removing<T: Into<Self>>(self, other: T) -> Self
Returns the result of removing the value from self
.
fn inserting<T: Into<Self>>(self, other: T) -> Self
Returns the result of inserting the value into self
.
fn toggling<T: Into<Self>>(self, other: T) -> Self
Returns the result of toggling the bits of the value in self
.
fn intersecting<T: Into<Self>>(self, other: T) -> Self
Returns the result of intersecting the bits of the value with self
.
fn setting<T: Into<Self>>(self, other: T, condition: bool) -> Self
Returns the result of setting the bits of the value in self
based on
condition
.
fn remove<T: Into<Self>>(&mut self, other: T) -> &mut Self
Removes the value from self
.
fn insert<T: Into<Self>>(&mut self, other: T) -> &mut Self
Inserts the value into self
.
fn toggle<T: Into<Self>>(&mut self, other: T) -> &mut Self
Toggles bits of the value in self
.
fn intersect<T: Into<Self>>(&mut self, other: T) -> &mut Self
Intersects the bits of the value with self
.
fn set<T: Into<Self>>(&mut self, other: T, condition: bool) -> &mut Self
Sets the bits of the value in self
based on condition
.