nibble_vec

Type Alias Nibblet

source
pub type Nibblet = NibbleVec<[u8; 64]>;
Expand description

A NibbleVec backed by a SmallVec with 64 inline element slots. This will not allocate until more than 64 elements are added.

Aliased Type§

struct Nibblet { /* private fields */ }

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: 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

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

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

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

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

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

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>