Skip to main content

CommandTrie

Struct CommandTrie 

Source
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>

Source

pub fn len(&self) -> usize

Number of entries stored in the trie.

Source

pub fn is_empty(&self) -> bool

Returns true when the trie holds no entries.

Source

pub fn get(&self, key: &str) -> Option<&T>

Exact lookup.

Source

pub fn contains(&self, key: &str) -> bool

Returns true when key is present in the trie.

Source

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.

Source

pub fn contains_prefix(&self, prefix: &str) -> bool

Returns true if any stored key starts with prefix.

Source

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.

Source

pub fn for_each(&self, f: impl FnMut(&str, &T))

Visit every (key, value) pair in alphabetical order without allocating per match.

Source

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.

Source

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.

Source

pub fn count_completions(&self, prefix: &str) -> usize

Number of entries whose key starts with prefix. Allocation-free.

Source

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).

Source

pub fn for_each_completion(&self, prefix: &str, f: impl FnMut(&str, &T))

Visit every completion of prefix without allocating per match.

Trait Implementations§

Source§

impl<T: Clone> Clone for CommandTrie<T>

Source§

fn clone(&self) -> CommandTrie<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for CommandTrie<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for CommandTrie<T>

Source§

fn default() -> Self

An empty, frozen trie (equivalent to CommandTrieBuilder::new().build()).

Source§

impl<'a, T> IntoIterator for &'a CommandTrie<T>

Source§

type Item = (String, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CommandTrie<T>

§

impl<T> RefUnwindSafe for CommandTrie<T>
where T: RefUnwindSafe,

§

impl<T> Send for CommandTrie<T>
where T: Send,

§

impl<T> Sync for CommandTrie<T>
where T: Sync,

§

impl<T> Unpin for CommandTrie<T>

§

impl<T> UnsafeUnpin for CommandTrie<T>

§

impl<T> UnwindSafe for CommandTrie<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.