pub struct BitVec { /* private fields */ }
Expand description
Bit vector with guaranteed [u8]
LSB 0 representation and safe mutable access to this slice.
Slices into the bit vector are guaranteed to have the unused bits on the last byte set to 0.
Implementations§
source§impl BitVec
impl BitVec
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs an empty BitVec
with the given capacity.
The bit vector will be able to hold at least capacity bits without reallocating. If capacity is 0, the bit vector will not allocate.
sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Constructs a BitVec
from bytes.
sourcepub fn from_bools(bools: &[bool]) -> Self
pub fn from_bools(bools: &[bool]) -> Self
Constructs a BitVec
from bools.
source§impl BitVec
impl BitVec
sourcepub fn with_bytes_mut<U, F: FnOnce(&mut [u8]) -> U>(&mut self, f: F) -> U
pub fn with_bytes_mut<U, F: FnOnce(&mut [u8]) -> U>(&mut self, f: F) -> U
Invokes the given function on a mut byte slice view of the data. After f
completes, the
trailing unused bits of the last byte are automatically set to 0.
sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Consumes the self
and returns the underlying Vec<u8>
of length ceil(self.len()/8)
.
The values of the bits in the last byte of Vec<u8>
beyond the length of the BitVec
are
0.
sourcepub fn set(&mut self, index: usize, value: bool)
pub fn set(&mut self, index: usize, value: bool)
Sets the bit at the given index
. Panics if index
exceeds length.
sourcepub unsafe fn get_unchecked(&self, index: usize) -> bool
pub unsafe fn get_unchecked(&self, index: usize) -> bool
Gets the bit at the given index
without bounds checking.
sourcepub unsafe fn set_unchecked(&mut self, index: usize, value: bool)
pub unsafe fn set_unchecked(&mut self, index: usize, value: bool)
Sets the bit at the given index
without bounds checking.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of booleans that the bitvec can hold without reallocating.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more booleans to be inserted in the given
BitVec
. The collection may reserve more space to avoid frequent reallocations.
sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shorten a vector, dropping excess elements.
If len
is greater than the vector’s current length, this has no effect.
Trait Implementations§
source§impl<'a> Extend<&'a bool> for BitVec
impl<'a> Extend<&'a bool> for BitVec
source§fn extend<T>(&mut self, iterable: T)where
T: IntoIterator<Item = &'a bool>,
fn extend<T>(&mut self, iterable: T)where T: IntoIterator<Item = &'a bool>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<bool> for BitVec
impl Extend<bool> for BitVec
source§fn extend<T>(&mut self, iterable: T)where
T: IntoIterator<Item = bool>,
fn extend<T>(&mut self, iterable: T)where T: IntoIterator<Item = bool>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)