pub struct CommandTrie<T> { /* private fields */ }Expand description
Compact, read-only radix trie produced by CommandTrieBuilder::build.
All storage lives in four boxed slices (nodes, labels, children,
child_first_bytes). All query methods are non-allocating in their
lookup paths; only methods that materialize keys (e.g. Iter::next)
allocate.
Implementations§
Source§impl<T> CommandTrie<T>
impl<T> CommandTrie<T>
Sourcepub fn longest_prefix_match<'a>(&self, input: &'a str) -> Option<(&'a str, &T)>
pub fn longest_prefix_match<'a>(&self, input: &'a str) -> Option<(&'a str, &T)>
Longest stored key that is a prefix of input, with its value.
The returned &str is a slice of input; its len() is the number
of bytes consumed.
Sourcepub fn contains_prefix(&self, prefix: &str) -> bool
pub fn contains_prefix(&self, prefix: &str) -> bool
Returns true if any stored key starts with prefix.
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Iterator over all (key, value) pairs in alphabetical order.
Each item allocates a fresh String for the key. For hot loops
prefer Self::for_each, which reuses an internal buffer.
Sourcepub fn for_each(&self, f: impl FnMut(&str, &T))
pub fn for_each(&self, f: impl FnMut(&str, &T))
Visit every (key, value) pair in alphabetical order without
allocating per match.
Sourcepub fn subtrie<'a>(&'a self, prefix: &str) -> Option<SubTrie<'a, T>>
pub fn subtrie<'a>(&'a self, prefix: &str) -> Option<SubTrie<'a, T>>
View of the entries whose key starts with prefix.
Returns None if no entry has that prefix. Prefer this when you need
to ask multiple questions about the same prefix.
Sourcepub fn completions<'a>(&'a self, prefix: &str) -> Vec<(String, &'a T)>
pub fn completions<'a>(&'a self, prefix: &str) -> Vec<(String, &'a T)>
All (key, value) pairs whose key starts with prefix.
Allocates a Vec and a String per match; for hot paths prefer
Self::for_each_completion.
Sourcepub fn count_completions(&self, prefix: &str) -> usize
pub fn count_completions(&self, prefix: &str) -> usize
Number of entries whose key starts with prefix. Allocation-free.
Sourcepub fn completion_prefix(&self, prefix: &str) -> Option<String>
pub fn completion_prefix(&self, prefix: &str) -> Option<String>
Longest string s such that every key matching prefix also starts
with s. Always s.starts_with(prefix); may extend past prefix
when only one branch is reachable. None if no entries match.
Allocates exactly one String (the returned value).
Trait Implementations§
Source§impl<T: Clone> Clone for CommandTrie<T>
impl<T: Clone> Clone for CommandTrie<T>
Source§fn clone(&self) -> CommandTrie<T>
fn clone(&self) -> CommandTrie<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more