pub struct BitVec { /* private fields */ }
Expand description
Represents a vector of bits.
Stores bits using u8
blocks for efficient storage.
Implementations§
Source§impl BitVec
impl BitVec
Sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Creates a new BitVec
with the specified capacity in bits.
Sourcepub fn zeroes(size: usize) -> Self
pub fn zeroes(size: usize) -> Self
Creates a new BitVec
with size
bits, all initialized to zero.
Sourcepub fn from_bools(bools: &[bool]) -> Self
pub fn from_bools(bools: &[bool]) -> Self
Creates a new BitVec
from a slice of booleans.
Sourcepub fn pop(&mut self) -> Option<bool>
pub fn pop(&mut self) -> Option<bool>
Removes the last bit from the vector and returns it.
Returns None
if the vector is empty.
Sourcepub fn get(&self, index: usize) -> Option<bool>
pub fn get(&self, index: usize) -> Option<bool>
Gets the value of the bit at index
(true if 1, false if 0).
Returns None
if the index is out of bounds.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> bool
pub unsafe fn get_unchecked(&self, index: usize) -> bool
Gets the value of the bit at the specified index without bounds checking.
§Safety
Caller must ensure index
is less than the length of the BitVec.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Returns the number of bits set to 1.
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Returns the number of bits set to 0.
Sourcepub fn iter(&self) -> BitIterator<'_> ⓘ
pub fn iter(&self) -> BitIterator<'_> ⓘ
Creates an iterator over the bits.
Trait Implementations§
Source§impl EncodeSize for BitVec
impl EncodeSize for BitVec
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Returns the encoded size of this value (in bytes).
Source§impl Read for BitVec
impl Read for BitVec
impl Eq for BitVec
impl StructuralPartialEq for BitVec
Auto Trait Implementations§
impl Freeze for BitVec
impl RefUnwindSafe for BitVec
impl Send for BitVec
impl Sync for BitVec
impl Unpin for BitVec
impl UnwindSafe for BitVec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more