Trait radix_trie::TrieKey
[−]
[src]
pub trait TrieKey: PartialEq + Eq { fn encode_bytes(&self) -> Vec<u8> { ... } fn encode(&self) -> NibbleVec { ... } }
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 NibbleVec
, 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
fn encode_bytes(&self) -> Vec<u8>
Encode a value as a vector of bytes.
fn encode(&self) -> NibbleVec
Encode a value as a NibbleVec.
Implementors
impl TrieKey for Vec<u8>
impl TrieKey for [u8]
impl TrieKey for String
impl TrieKey for str
impl<'a, T: ?Sized + TrieKey> TrieKey for &'a T
impl<'a, T: ?Sized + TrieKey> TrieKey for &'a mut T
impl TrieKey for i8
impl TrieKey for u8
impl TrieKey for PathBuf
impl TrieKey for Path
impl<T> TrieKey for LittleEndian<T> where
T: Eq + Copy,impl<T> TrieKey for BigEndian<T> where
T: Eq + Copy,impl TrieKey for u16
impl TrieKey for u32
impl TrieKey for u64
impl TrieKey for i16
impl TrieKey for i32
impl TrieKey for i64
impl TrieKey for usize
impl TrieKey for isize