BitCollection

Trait BitCollection 

Source
pub trait BitCollection:
    From<<Self as IntoIterator>::Item>
    + From<BitIter<Self>>
    + IntoIterator<IntoIter = BitIter<Self>>
    + FromIterator<<Self as IntoIterator>::Item>
    + Extend<<Self as IntoIterator>::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;
Show 25 methods // Required methods 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; // Provided methods 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 { ... }
}
Expand description

A type that represents a collection of bits that can be iterated over.

Required Associated Constants§

Source

const FULL: Self

A full instance with all bits set.

Source

const EMPTY: Self

An empty instance with no bits set.

Required Methods§

Source

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.

Source

fn is_empty(&self) -> bool

Returns whether self is empty.

Source

fn has_multiple(&self) -> bool

Returns whether self has multiple bits set.

Source

unsafe fn lsb_unchecked(&self) -> Self::Item

Returns the least significant bit in self without checking whether self is empty.

Source

unsafe fn msb_unchecked(&self) -> Self::Item

Returns the most significant bit in self without checking whether self is empty.

Source

fn remove_lsb(&mut self)

Removes the least significant bit from self.

Source

fn remove_msb(&mut self)

Removes the most significant bit from self.

Source

fn pop_lsb(&mut self) -> Option<Self::Item>

Removes the least significant bit from self and returns it.

Source

fn pop_msb(&mut self) -> Option<Self::Item>

Removes the most significant bit from self and returns it.

Source

fn contains<T: Into<Self>>(&self, _: T) -> bool

Returns whether self contains the value.

Provided Methods§

Source

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

Source

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);
Source

fn into_bit(self) -> Option<Self::Item>

Converts self into the only bit set.

Source

fn lsb(&self) -> Option<Self::Item>

Returns the least significant bit in self if self is not empty.

Source

fn msb(&self) -> Option<Self::Item>

Returns the most significant bit in self if self is not empty.

Source

fn removing<T: Into<Self>>(self, other: T) -> Self

Returns the result of removing the value from self.

Source

fn inserting<T: Into<Self>>(self, other: T) -> Self

Returns the result of inserting the value into self.

Source

fn toggling<T: Into<Self>>(self, other: T) -> Self

Returns the result of toggling the bits of the value in self.

Source

fn intersecting<T: Into<Self>>(self, other: T) -> Self

Returns the result of intersecting the bits of the value with self.

Source

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.

Source

fn remove<T: Into<Self>>(&mut self, other: T) -> &mut Self

Removes the value from self.

Source

fn insert<T: Into<Self>>(&mut self, other: T) -> &mut Self

Inserts the value into self.

Source

fn toggle<T: Into<Self>>(&mut self, other: T) -> &mut Self

Toggles bits of the value in self.

Source

fn intersect<T: Into<Self>>(&mut self, other: T) -> &mut Self

Intersects the bits of the value with self.

Source

fn set<T: Into<Self>>(&mut self, other: T, condition: bool) -> &mut Self

Sets the bits of the value in self based on condition.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§