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§

Create an empty nibble vector.

Create a nibble vector from a vector of bytes.

Each byte is split into two 4-bit entries (MSB, LSB).

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

Converts a nibble vector into a byte vector.

This consumes the nibble vector, so we do not need to copy its contents.

Get the number of elements stored in the vector.

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

Fetch a single entry from the vector.

Guaranteed to be a value in the interval [0, 15].

Panics if idx >= self.len().

Add a single nibble to the vector.

Only the 4 least-significant bits of the value are used.

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

Append another nibble vector whilst consuming this vector.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.

Compare a NibbleVec and a slice of bytes element-by-element. Bytes are not interpreted as two NibbleVec entries.

This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.