[−][src]Struct nibble_vec::NibbleVec
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
impl<A: Array<Item = u8>> NibbleVec<A>
[src]
pub fn new() -> NibbleVec<A>
[src]
Create an empty nibble vector.
pub fn from_byte_vec(vec: Vec<u8>) -> NibbleVec<A>
[src]
Create a nibble vector from a vector of bytes.
Each byte is split into two 4-bit entries (MSB, LSB).
pub fn as_bytes(&self) -> &[u8]
[src]
Returns a byte slice of the nibble vector's contents.
pub fn into_bytes(self) -> Vec<u8>
[src]
Converts a nibble vector into a byte vector.
This consumes the nibble vector, so we do not need to copy its contents.
pub fn len(&self) -> usize
[src]
Get the number of elements stored in the vector.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the nibble vector has a length of 0.
pub fn get(&self, idx: usize) -> u8
[src]
Fetch a single entry from the vector.
Guaranteed to be a value in the interval [0, 15].
Panics if idx >= self.len()
.
pub fn push(&mut self, val: u8)
[src]
Add a single nibble to the vector.
Only the 4 least-significant bits of the value are used.
pub fn split(&mut self, idx: usize) -> NibbleVec<A>
[src]
Split the vector into two parts.
All elements at or following the given index are returned in a new NibbleVec
,
with exactly idx
elements remaining in this vector.
Panics if idx > self.len()
.
pub fn join(self, other: &NibbleVec<A>) -> NibbleVec<A>
[src]
Append another nibble vector whilst consuming this vector.
Trait Implementations
impl<A: Clone + Array<Item = u8>> Clone for NibbleVec<A>
[src]
impl<A: Array<Item = u8>> Debug for NibbleVec<A>
[src]
impl<A: Default + Array<Item = u8>> Default for NibbleVec<A>
[src]
impl<A: Array<Item = u8>> Eq for NibbleVec<A>
[src]
impl<'a, A: Array<Item = u8>> From<&'a [u8]> for NibbleVec<A>
[src]
impl<A: Array<Item = u8>> From<Vec<u8>> for NibbleVec<A>
[src]
impl<A: Array<Item = u8>> Into<Vec<u8>> for NibbleVec<A>
[src]
impl<'a, A: Array<Item = u8>> Into<Vec<u8>> for &'a NibbleVec<A>
[src]
impl<A: Array<Item = u8>> PartialEq<[u8]> for NibbleVec<A>
[src]
Compare a NibbleVec
and a slice of bytes element-by-element.
Bytes are not interpreted as two NibbleVec
entries.
impl<A: Array<Item = u8>> PartialEq<NibbleVec<A>> for NibbleVec<A>
[src]
Auto Trait Implementations
impl<A> RefUnwindSafe for NibbleVec<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> Send for NibbleVec<A>
impl<A> Sync for NibbleVec<A> where
A: Sync,
A: Sync,
impl<A> Unpin for NibbleVec<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for NibbleVec<A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,