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§
sourcefn encode_bytes(&self) -> Vec<u8>
fn encode_bytes(&self) -> Vec<u8>
Encode a value as a vector of bytes.