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>

source

pub fn new() -> NibbleVec<A>

Create an empty nibble vector.

source

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).

source

pub fn as_bytes(&self) -> &[u8]

Returns a byte slice of the nibble vector’s contents.

source

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.

source

pub fn len(&self) -> usize

Get the number of elements stored in the vector.

source

pub fn is_empty(&self) -> bool

Returns true if the nibble vector has a length of 0.

source

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().

source

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.

source

pub fn split(&mut self, idx: usize) -> NibbleVec<A>

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().

source

pub fn join(self, other: &NibbleVec<A>) -> NibbleVec<A>

Append another nibble vector whilst consuming this vector.

Trait Implementations§

source§

impl<A: Clone + Array<Item = u8>> Clone for NibbleVec<A>

source§

fn clone(&self) -> NibbleVec<A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A: Array<Item = u8>> Debug for NibbleVec<A>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A: Default + Array<Item = u8>> Default for NibbleVec<A>

source§

fn default() -> NibbleVec<A>

Returns the “default value” for a type. Read more
source§

impl<'a, A: Array<Item = u8>> From<&'a [u8]> for NibbleVec<A>

source§

fn from(v: &[u8]) -> NibbleVec<A>

Converts to this type from the input type.
source§

impl<A: Array<Item = u8>> From<Vec<u8>> for NibbleVec<A>

source§

fn from(v: Vec<u8>) -> NibbleVec<A>

Converts to this type from the input type.
source§

impl<'a, A: Array<Item = u8>> Into<Vec<u8>> for &'a NibbleVec<A>

source§

fn into(self) -> Vec<u8>

Converts this type into the (usually inferred) input type.
source§

impl<A: Array<Item = u8>> Into<Vec<u8>> for NibbleVec<A>

source§

fn into(self) -> Vec<u8>

Converts this type into the (usually inferred) input type.
source§

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§

fn eq(&self, other: &[u8]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<A: Array<Item = u8>> PartialEq for NibbleVec<A>

source§

fn eq(&self, other: &NibbleVec<A>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.