pub struct Trie<K, V>{ /* private fields */ }Expand description
A singly initialised Trie mapping key sequences to a value.
It is not permitted for values to be mapped to a key that is a prefix of another key also existing in the same Trie.
There are convenience methods provided for Trie<char, V> for when &str values are used as keys.
Implementations§
Source§impl<K, V> Trie<K, V>
impl<K, V> Trie<K, V>
Sourcepub fn try_from_iter(
it: impl IntoIterator<Item = (Vec<K>, V)>,
) -> Result<Self, &'static str>
pub fn try_from_iter( it: impl IntoIterator<Item = (Vec<K>, V)>, ) -> Result<Self, &'static str>
Construct a new Trie from key-value pairs.
Will panic if there are any key collisions or if there are any sequences that nest under a prefix that is already required to hold a value
Sourcepub fn merge(self, other: Self) -> Result<Self, &'static str>
pub fn merge(self, other: Self) -> Result<Self, &'static str>
Merge two Tries.
If the resulting Trie would be invalid to construct directly, an error is returned.
Consumes both inputs.
Sourcepub fn merge_overriding(self, other: Self) -> Result<Self, &'static str>
pub fn merge_overriding(self, other: Self) -> Result<Self, &'static str>
Merge two Tries preferring keys from other in the case of collisions.
If the resulting Trie would be invalid to construct directly, an error is returned.
Consumes both inputs.
Sourcepub fn get<'a>(&'a self, key: &[K]) -> QueryResult<'a, V>
pub fn get<'a>(&'a self, key: &[K]) -> QueryResult<'a, V>
Query this Trie for a given key or key prefix
If the key maps to a leaf then the value is returned, if it maps to a sub-trie then
Partial is returned to denote that the given key is a parent of one or more values. If
the key is not found within the Trie then Missing is returned.
Trait Implementations§
impl<K, V> Eq for Trie<K, V>
Source§impl<K, V> PartialEq for Trie<K, V>
impl<K, V> PartialEq for Trie<K, V>
impl<K, V> StructuralPartialEq for Trie<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for Trie<K, V>
impl<K, V> RefUnwindSafe for Trie<K, V>where
V: RefUnwindSafe,
K: RefUnwindSafe,
impl<K, V> Send for Trie<K, V>
impl<K, V> Sync for Trie<K, V>
impl<K, V> Unpin for Trie<K, V>
impl<K, V> UnsafeUnpin for Trie<K, V>
impl<K, V> UnwindSafe for Trie<K, V>where
V: RefUnwindSafe,
K: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.