[][src]Struct trie_db::NibbleSlice

pub struct NibbleSlice<'a> { /* fields omitted */ }

Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.

This is an immutable struct. No operations actually change it.

Example

use patricia_trie::nibbleslice::NibbleSlice;
fn main() {
  let d1 = &[0x01u8, 0x23, 0x45];
  let d2 = &[0x34u8, 0x50, 0x12];
  let d3 = &[0x00u8, 0x12];
  let n1 = NibbleSlice::new(d1);			// 0,1,2,3,4,5
  let n2 = NibbleSlice::new(d2);			// 3,4,5,0,1,2
  let n3 = NibbleSlice::new_offset(d3, 1);	// 0,1,2
  assert!(n1 > n3);							// 0,1,2,... > 0,1,2
  assert!(n1 < n2);							// 0,... < 3,...
  assert!(n2.mid(3) == n3);					// 0,1,2 == 0,1,2
  assert!(n1.starts_with(&n3));
  assert_eq!(n1.common_prefix(&n3), 3);
  assert_eq!(n2.mid(3).common_prefix(&n1), 3);
}

Methods

impl<'a> NibbleSlice<'a>[src]

pub fn new(data: &'a [u8]) -> Self[src]

Create a new nibble slice with the given byte-slice.

pub fn new_offset(data: &'a [u8], offset: usize) -> Self[src]

Create a new nibble slice with the given byte-slice with a nibble offset.

pub fn new_composed(a: &NibbleSlice<'a>, b: &NibbleSlice<'a>) -> Self[src]

Create a composed nibble slice; one followed by the other.

pub fn iter(&'a self) -> NibbleSliceIterator<'a>[src]

Get an iterator for the series of nibbles.

pub fn from_encoded(data: &'a [u8]) -> (NibbleSlice, bool)[src]

Create a new nibble slice from the given HPE encoded data (e.g. output of encoded()).

pub fn is_empty(&self) -> bool[src]

Is this an empty slice?

pub fn len(&self) -> usize[src]

Get the length (in nibbles, naturally) of this slice.

pub fn at(&self, i: usize) -> u8[src]

Get the nibble at position i.

pub fn mid(&self, i: usize) -> NibbleSlice<'a>[src]

Return object which represents a view on to this slice (further) offset by i nibbles.

pub fn starts_with(&self, them: &Self) -> bool[src]

Do we start with the same nibbles as the whole of them?

pub fn common_prefix(&self, them: &Self) -> usize[src]

How many of the same nibbles at the beginning do we match with them?

pub fn encoded(&self, is_leaf: bool) -> ElasticArray36<u8>[src]

Encode while nibble slice in prefixed hex notation, noting whether it is_leaf.

pub fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> ElasticArray36<u8>[src]

Encode only the leftmost n bytes of the nibble slice in prefixed hex notation, noting whether it is_leaf.

Trait Implementations

impl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl<'a> Eq for NibbleSlice<'a>[src]

impl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> Ord for NibbleSlice<'a>[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more

impl<'a> Clone for NibbleSlice<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Copy for NibbleSlice<'a>[src]

impl<'a> Debug for NibbleSlice<'a>[src]

Auto Trait Implementations

impl<'a> Send for NibbleSlice<'a>

impl<'a> Sync for NibbleSlice<'a>

Blanket Implementations

impl<T> MaybeDebug for T where
    T: Debug
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> MaybeDebug for T where
    T: Debug
[src]