Struct trie_db::NibbleSlice
source · [−]pub struct NibbleSlice<'a> { /* private fields */ }
Expand description
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);
}
Implementations
sourceimpl<'a> NibbleSlice<'a>
impl<'a> NibbleSlice<'a>
sourcepub fn new_offset(data: &'a [u8], offset: usize) -> Self
pub fn new_offset(data: &'a [u8], offset: usize) -> Self
Create a new nibble slice with the given byte-slice with a nibble offset.
sourcepub fn new_composed(a: &NibbleSlice<'a>, b: &NibbleSlice<'a>) -> Self
pub fn new_composed(a: &NibbleSlice<'a>, b: &NibbleSlice<'a>) -> Self
Create a composed nibble slice; one followed by the other.
sourcepub fn from_encoded(data: &'a [u8]) -> (NibbleSlice<'_>, bool)
pub fn from_encoded(data: &'a [u8]) -> (NibbleSlice<'_>, bool)
Create a new nibble slice from the given HPE encoded data (e.g. output of encoded()
).
sourcepub fn mid(&self, i: usize) -> NibbleSlice<'a>
pub fn mid(&self, i: usize) -> NibbleSlice<'a>
Return object which represents a view on to this slice (further) offset by i
nibbles.
sourcepub fn starts_with(&self, them: &Self) -> bool
pub fn starts_with(&self, them: &Self) -> bool
Do we start with the same nibbles as the whole of them
?
sourcepub fn common_prefix(&self, them: &Self) -> usize
pub fn common_prefix(&self, them: &Self) -> usize
How many of the same nibbles at the beginning do we match with them
?
sourcepub fn encoded(&self, is_leaf: bool) -> ElasticArray36<u8>
pub fn encoded(&self, is_leaf: bool) -> ElasticArray36<u8>
Encode while nibble slice in prefixed hex notation, noting whether it is_leaf
.
sourcepub fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> ElasticArray36<u8>
pub fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> ElasticArray36<u8>
Encode only the leftmost n
bytes of the nibble slice in prefixed hex notation,
noting whether it is_leaf
.
Trait Implementations
sourceimpl<'a> Clone for NibbleSlice<'a>
impl<'a> Clone for NibbleSlice<'a>
sourcefn clone(&self) -> NibbleSlice<'a>
fn clone(&self) -> NibbleSlice<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for NibbleSlice<'a>
impl<'a> Debug for NibbleSlice<'a>
sourceimpl<'a> Ord for NibbleSlice<'a>
impl<'a> Ord for NibbleSlice<'a>
sourceimpl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>
impl<'a> PartialEq<NibbleSlice<'a>> for NibbleSlice<'a>
sourceimpl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>
impl<'a> PartialOrd<NibbleSlice<'a>> for NibbleSlice<'a>
sourcefn partial_cmp(&self, them: &Self) -> Option<Ordering>
fn partial_cmp(&self, them: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<'a> Copy for NibbleSlice<'a>
impl<'a> Eq for NibbleSlice<'a>
impl<'a> StructuralEq for NibbleSlice<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for NibbleSlice<'a>
impl<'a> Send for NibbleSlice<'a>
impl<'a> Sync for NibbleSlice<'a>
impl<'a> Unpin for NibbleSlice<'a>
impl<'a> UnwindSafe for NibbleSlice<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more