Trait radix_trie::TrieKey

source ·
pub trait TrieKey: PartialEq + Eq {
    // Provided methods
    fn encode_bytes(&self) -> Vec<u8> { ... }
    fn encode(&self) -> Nibblet { ... }
}
Expand description

Trait for types which can be used to key a Radix Trie.

Types that implement this trait should be convertible to a vector of half-bytes (nibbles) such that no two instances of the type convert to the same vector. To protect against faulty behaviour, the trie will panic if it finds two distinct keys of type K which encode to the same Nibblet, so be careful!

If you would like to implement this trait for your own type, you need to implement either encode_bytes or encode. You only need to implement one of the two. If you don’t implement one, your code will panic as soon you use the trie. There is no performance penalty for implementing encode_bytes instead of encode, so it is preferred except in the case where you require half-byte precision.

Many standard types implement this trait already. Integer types are encoded big-endian by default but can be encoded little-endian using the LittleEndian<T> wrapper type.

Provided Methods§

source

fn encode_bytes(&self) -> Vec<u8>

Encode a value as a vector of bytes.

source

fn encode(&self) -> Nibblet

Encode a value as a NibbleVec.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TrieKey for i8

source§

impl TrieKey for i16

source§

impl TrieKey for i32

source§

impl TrieKey for i64

source§

impl TrieKey for isize

source§

impl TrieKey for str

source§

impl TrieKey for u8

source§

impl TrieKey for u16

source§

impl TrieKey for u32

source§

impl TrieKey for u64

source§

impl TrieKey for usize

source§

impl TrieKey for String

source§

impl TrieKey for Vec<i16>

source§

impl TrieKey for Vec<i32>

source§

impl TrieKey for Vec<i64>

source§

impl TrieKey for Vec<isize>

source§

impl TrieKey for Vec<u8>

source§

impl TrieKey for Vec<u16>

source§

impl TrieKey for Vec<u32>

source§

impl TrieKey for Vec<u64>

source§

impl TrieKey for Vec<usize>

source§

impl TrieKey for Path

source§

impl TrieKey for PathBuf

source§

impl TrieKey for [u8]

source§

impl<'a, T: ?Sized + TrieKey> TrieKey for &'a T

source§

impl<'a, T: ?Sized + TrieKey> TrieKey for &'a mut T

source§

impl<T> TrieKey for BigEndian<T>
where T: Eq + Copy,

source§

impl<T> TrieKey for LittleEndian<T>
where T: Eq + Copy,

Implementors§