Skip to main content

CommandTrieBuilder

Struct CommandTrieBuilder 

Source
pub struct CommandTrieBuilder<T> { /* private fields */ }
Expand description

Mutable trie used during the build phase.

Call Self::build to produce a frozen CommandTrie when you are done inserting.

Implementations§

Source§

impl<T> CommandTrieBuilder<T>

Source

pub fn new() -> Self

Create a new, empty builder.

Source

pub fn len(&self) -> usize

Number of entries currently in the builder.

Source

pub fn is_empty(&self) -> bool

Returns true when no entries have been inserted.

Source

pub fn clear(&mut self)

Remove every entry, returning the builder to its initial state.

Source

pub fn insert(&mut self, key: &str, value: T) -> Option<T>

Insert key with value. Returns the previous value, if any.

Any &str is accepted; the radix splits on UTF-8 char boundaries so every internal edge label remains valid UTF-8.

Source

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

Remove key and return its value, if present. Maintains the radix invariant by pruning empty branches and merging single-child passthroughs with their parent edge.

Source

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

Exact lookup against the builder.

Source

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

Returns true when key is present in the builder.

Source

pub fn build(self) -> CommandTrie<T>

Freeze the builder into a compact, read-only CommandTrie.

Performs one DFS over the builder trie and writes the result into four contiguous slabs (nodes, labels, children, child_first_bytes). After this call the frozen trie has exactly four heap allocations regardless of trie size.

§Panics

If the trie’s total node count, total label bytes, or total edge count would exceed u16::MAX (65,535). The frozen representation stores every offset and node id as a u16 to halve the structural slabs. The worst case for N inserted entries is 2N + 1 nodes, so this caps the trie at roughly 32,767 entries — enough for any realistic command set.

Trait Implementations§

Source§

impl<T: Clone> Clone for CommandTrieBuilder<T>

Source§

fn clone(&self) -> CommandTrieBuilder<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 CommandTrieBuilder<T>

Source§

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

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

impl<T> Default for CommandTrieBuilder<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: AsRef<str>, T> Extend<(K, T)> for CommandTrieBuilder<T>

Source§

fn extend<I: IntoIterator<Item = (K, T)>>(&mut self, iter: I)

Insert each (key, value) from iter.

Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: AsRef<str>, T> FromIterator<(K, T)> for CommandTrieBuilder<T>

Source§

fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self

Build a CommandTrieBuilder from an iterator of (key, value) pairs.

Auto Trait Implementations§

§

impl<T> Freeze for CommandTrieBuilder<T>
where T: Freeze,

§

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

§

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

§

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

§

impl<T> Unpin for CommandTrieBuilder<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for CommandTrieBuilder<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for CommandTrieBuilder<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.