Skip to main content

SubTrie

Struct SubTrie 

Source
pub struct SubTrie<'a, T> { /* private fields */ }
Expand description

View over the subset of a CommandTrie whose keys share a common prefix.

Construct via CommandTrie::subtrie. Guaranteed non-empty.

Implementations§

Source§

impl<'a, T> SubTrie<'a, T>

Source

pub fn common_prefix(&self) -> &str

Longest prefix shared by every entry in the view.

Source

pub fn extension(&self) -> &str

Bytes between the originally queried prefix and Self::common_prefix.

This is exactly what a fish-style line editor should splice into the buffer on TAB: the unambiguous auto-extension implied by what the user has typed so far. Empty when the typed prefix is already at a branch point (caller should then display the menu of completions).

Source

pub fn is_unique(&self) -> bool

true when exactly one entry matches — the caller can commit it and stop prompting. O(1).

Source

pub fn value(&self) -> Option<&'a T>

Value at this view’s deepest node, when that node itself holds a value (i.e. Self::common_prefix is itself a stored key). Returns None for a pure branch-point view.

Source

pub fn unique_value(&self) -> Option<&'a T>

The single matching value when this view contains exactly one entry, else None. Combines Self::is_unique and Self::value; spares the caller a follow-up trie.get(sub.common_prefix()).

Source

pub fn len(&self) -> usize

Number of entries in the view. Walks the subtrie.

Source

pub fn is_empty(&self) -> bool

Always false — a SubTrie only exists when at least one entry matches.

Source

pub fn iter(&self) -> Iter<'a, T>

Iterator over (key, value) pairs in this view, alphabetically.

Clones common_prefix into the iterator’s buffer. If you only walk the view once, prefer subtrie.into_iter(), which moves the buffer in instead.

Source

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

Visit every entry in the view without allocating per match.

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for SubTrie<'a, T>

Source§

fn clone(&self) -> SubTrie<'a, 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 for SubTrie<'_, T>

Source§

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

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

impl<'a, T> IntoIterator for &SubTrie<'a, 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
Source§

impl<'a, T> IntoIterator for SubTrie<'a, T>

Source§

fn into_iter(self) -> Self::IntoIter

Moves common_prefix into the iterator’s buffer, avoiding the clone that (&subtrie).into_iter() would perform.

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?

Auto Trait Implementations§

§

impl<'a, T> Freeze for SubTrie<'a, T>

§

impl<'a, T> RefUnwindSafe for SubTrie<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for SubTrie<'a, T>
where T: Sync,

§

impl<'a, T> Sync for SubTrie<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for SubTrie<'a, T>

§

impl<'a, T> UnsafeUnpin for SubTrie<'a, T>

§

impl<'a, T> UnwindSafe for SubTrie<'a, T>
where T: RefUnwindSafe,

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.