Struct BitSpan

Source
pub struct BitSpan<'a, T: BitWord> { /* private fields */ }
Expand description

A non-owning read-only view into a bit array.

BitSpan provides a view into a sequence of bits stored in memory, allowing read-only access to individual bits or ranges of bits. It can be used to efficiently operate on a subset of bits without copying or allocating memory.

The span is defined by:

  • A pointer to the start of the word array
  • A bit offset from the start of the first word
  • A length in bits

§Safety

This type uses raw pointers internally. The caller must ensure that:

  • The referenced memory remains valid for the lifetime of the span
  • The offset and length parameters don’t cause out-of-bounds access

Implementations§

Source§

impl<'a, T: BitWord> BitSpan<'a, T>

Source

pub fn from_raw_parts(ptr: *const T, offset: usize, len: usize) -> Self

Creates a new BitSpan from raw parts.

This function allows creating a span directly from a raw pointer, which is useful for interfacing with external memory or creating views into existing bit arrays.

§Arguments
  • ptr - A pointer to the word array (will be converted to non-null)
  • offset - The bit offset from the start of the first word
  • len - The number of bits in the span
§Safety

The caller must ensure that:

  • The pointer is valid for reads of len bits starting at offset
  • The memory remains valid for the lifetime of the returned span

If ptr is null, a dangling pointer will be used. This is safe as long as len is 0, but will lead to undefined behavior otherwise.

Trait Implementations§

Source§

impl<'a, 'b, T: BitWord> BitAndAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>

Source§

fn bitand_assign(&mut self, rhs: &'b BitSpan<'b, T>)

Performs the &= operation. Read more
Source§

impl<'a, 'b, T: BitWord> BitOrAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>

Source§

fn bitor_assign(&mut self, rhs: &'b BitSpan<'b, T>)

Performs the |= operation. Read more
Source§

impl<'a, T: BitWord> BitRead for BitSpan<'a, T>

Source§

type Iter<'b> = BitSpanIter<'b, T> where Self: 'b

The iterator type returned by the iter method.

Source§

fn len(&self) -> usize

Returns the number of bits in the span.

Source§

fn is_empty(&self) -> bool

Returns true if the span is empty or contains no set bits.

This implementation considers a span empty if either:

  • It has zero length
  • It has no bits set to 1
Source§

fn test(&self, idx: usize) -> bool

Tests if the bit at the given index is set.

§Arguments
  • idx - The index of the bit to test
§Returns

true if the bit is set, false otherwise

§Panics

Panics if idx is out of bounds (>= self.len).

Source§

fn count_ones(&self) -> usize

Counts the number of bits set to 1 in the span.

§Returns

The number of bits set to 1

Source§

fn all(&self) -> bool

Returns true if all bits in the span are set to 1.

§Returns

true if the span is non-empty and all bits are set to 1, false otherwise

Source§

fn any(&self) -> bool

Returns true if any bit in the span is set to 1.

§Returns

true if at least one bit is set to 1, false otherwise

Source§

fn iter(&self) -> Self::Iter<'_>

Returns an iterator over the indices of bits set to 1.

§Returns

An iterator that yields the indices of all bits set to 1 in ascending order

Source§

fn none(&self) -> bool

Source§

impl<'a, 'b, T: BitWord> BitXorAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>

Source§

fn bitxor_assign(&mut self, rhs: &'b BitSpan<'b, T>)

Performs the ^= operation. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for BitSpan<'a, T>

§

impl<'a, T> RefUnwindSafe for BitSpan<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for BitSpan<'a, T>

§

impl<'a, T> !Sync for BitSpan<'a, T>

§

impl<'a, T> Unpin for BitSpan<'a, T>

§

impl<'a, T> UnwindSafe for BitSpan<'a, T>
where T: RefUnwindSafe,

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