Struct nibble_vec::NibbleVec
source · pub struct NibbleVec<A: Array<Item = u8>> { /* private fields */ }
Expand description
A data-structure for storing a sequence of 4-bit values.
Values are stored in a Vec<u8>
, with two values per byte.
Values at even indices are stored in the most-significant half of their byte, while values at odd indices are stored in the least-significant half.
Imagine a vector of MSB first bytes, and you’ll be right.
n = [_ _ | _ _ | _ _]
Implementations§
source§impl<A: Array<Item = u8>> NibbleVec<A>
impl<A: Array<Item = u8>> NibbleVec<A>
sourcepub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec<A>
pub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec<A>
Create a nibble vector from a vector of bytes.
Each byte is split into two 4-bit entries (MSB, LSB).
sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Converts a nibble vector into a byte vector.
This consumes the nibble vector, so we do not need to copy its contents.
sourcepub fn get(&self, idx: usize) -> u8
pub fn get(&self, idx: usize) -> u8
Fetch a single entry from the vector.
Guaranteed to be a value in the interval [0, 15].
Panics if idx >= self.len()
.
sourcepub fn push(&mut self, val: u8)
pub fn push(&mut self, val: u8)
Add a single nibble to the vector.
Only the 4 least-significant bits of the value are used.
Trait Implementations§
source§impl<A: Array<Item = u8>> PartialEq<[u8]> for NibbleVec<A>
impl<A: Array<Item = u8>> PartialEq<[u8]> for NibbleVec<A>
Compare a NibbleVec
and a slice of bytes element-by-element.
Bytes are not interpreted as two NibbleVec
entries.
source§impl<A: Array<Item = u8>> PartialEq for NibbleVec<A>
impl<A: Array<Item = u8>> PartialEq for NibbleVec<A>
impl<A: Array<Item = u8>> Eq for NibbleVec<A>
Auto Trait Implementations§
impl<A> Freeze for NibbleVec<A>where
A: Freeze,
impl<A> RefUnwindSafe for NibbleVec<A>where
A: RefUnwindSafe,
impl<A> Send for NibbleVec<A>
impl<A> Sync for NibbleVec<A>where
A: Sync,
impl<A> Unpin for NibbleVec<A>where
A: Unpin,
impl<A> UnwindSafe for NibbleVec<A>where
A: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)