pub struct BitSpanMut<'a, T: BitWord> { /* private fields */ }
Expand description
A non-owning mutable view into a bit array.
BitSpanMut
provides a view into a sequence of bits stored in memory, allowing
both reading and writing of 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
- No other references (mutable or immutable) to the same memory are used during the lifetime of the span to avoid aliasing violations
- The offset and length parameters don’t cause out-of-bounds access
Implementations§
Source§impl<'a, T: BitWord> BitSpanMut<'a, T>
impl<'a, T: BitWord> BitSpanMut<'a, T>
Sourcepub fn from_raw_parts_mut(ptr: *mut T, offset: usize, len: usize) -> Self
pub fn from_raw_parts_mut(ptr: *mut T, offset: usize, len: usize) -> Self
Creates a new BitSpanMut
from raw parts.
This function allows creating a mutable span directly from a raw pointer, which is useful for interfacing with external memory or creating mutable views into existing bit arrays.
§Arguments
ptr
- A mutable pointer to the word array (will be converted to non-null)offset
- The bit offset from the start of the first wordlen
- The number of bits in the span
§Safety
The caller must ensure that:
- The pointer is valid for reads and writes of
len
bits starting atoffset
- The memory remains valid for the lifetime of the returned span
- No other references to the same memory are used during the lifetime of the 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>
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>)
fn bitand_assign(&mut self, rhs: &'b BitSpan<'b, T>)
&=
operation. Read moreSource§impl<'a, 'b, T: BitWord> BitOrAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
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>)
fn bitor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
|=
operation. Read moreSource§impl<'a, T: BitWord> BitRead for BitSpanMut<'a, T>
impl<'a, T: BitWord> BitRead for BitSpanMut<'a, T>
Source§type Iter<'b> = BitSpanIter<'b, T>
where
Self: 'b
type Iter<'b> = BitSpanIter<'b, T> where Self: 'b
The iterator type returned by the iter
method.
Source§fn is_empty(&self) -> bool
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 count_ones(&self) -> usize
fn count_ones(&self) -> usize
Source§fn all(&self) -> bool
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
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<'_>
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
fn none(&self) -> bool
Source§impl<'a, T: BitWord> BitWrite for BitSpanMut<'a, T>
impl<'a, T: BitWord> BitWrite for BitSpanMut<'a, T>
Source§fn test_and_set(&mut self, idx: usize) -> bool
fn test_and_set(&mut self, idx: usize) -> bool
Source§fn fill(&mut self)
fn fill(&mut self)
Sets all bits in the span to 1.
This method efficiently sets all bits within the span’s range to 1, taking care to only modify bits that are part of the span.
Source§impl<'a, 'b, T: BitWord> BitXorAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
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>)
fn bitxor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
^=
operation. Read more