Skip to main content

CommandNameIndex

Struct CommandNameIndex 

Source
pub struct CommandNameIndex { /* private fields */ }
Expand description

Name-based command index for ex-command resolution.

Maps command names to their CommandId and the underlying Command trait object (for complete() delegation).

§Lifecycle

  1. Server builds this at bootstrap from CommandRegistry
  2. Stored in ServiceRegistry as Arc<CommandNameIndex>
  3. Modules query it for name→id resolution and tab-completion

Implementations§

Source§

impl CommandNameIndex

Source

pub fn new() -> Self

Create an empty index.

Source

pub fn insert(&mut self, name: String, id: CommandId, cmd: Arc<dyn Command>)

Insert a command by name.

Each name (alias) maps to the same CommandId and Command. Last-wins if the same name is inserted twice.

Source

pub fn resolve(&self, name: &str) -> Option<&CommandId>

Resolve a command name to its CommandId.

Source

pub fn resolve_entry(&self, name: &str) -> Option<(&CommandId, &dyn Command)>

Resolve a command name to its CommandId and Command trait object.

Unlike resolve(), this returns the full entry so callers can access Command::args() for spec-driven argument binding.

Source

pub fn resolve_prefix( &self, name: &str, ) -> Result<Option<(&CommandId, &dyn Command)>, AmbiguousPrefix>

Resolve a command by exact name or unambiguous prefix.

Resolution order:

  1. Exact match — returned immediately (highest priority)
  2. Prefix search — if exactly one distinct command matches, return it
  3. Multiple aliases of the same command are deduplicated (not ambiguous)
  4. Multiple distinct commands — return AmbiguousPrefix error

Returns Ok(None) for empty input or no matches.

§Errors

Returns AmbiguousPrefix when the prefix matches two or more distinct commands (e.g., :s matching both :set and :split).

Source

pub fn complete_args(&self, name: &str, partial: &str) -> Vec<String>

Get argument completions for a named command.

Delegates to the command’s complete() method.

Source

pub fn search_by_prefix(&self, prefix: &str) -> Vec<(&CommandId, &dyn Command)>

Search for commands whose names start with prefix.

Returns deduplicated results (one entry per unique CommandId).

Source

pub fn list_all(&self) -> Vec<(&CommandId, &dyn Command)>

List all unique commands in the index.

Source

pub fn count(&self) -> usize

Get the number of unique commands (not aliases).

Trait Implementations§

Source§

impl Debug for CommandNameIndex

Source§

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

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

impl Default for CommandNameIndex

Source§

fn default() -> Self

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

impl Service for CommandNameIndex

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more