pub trait CommandHandler<Ctx: ?Sized>: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn category(&self) -> SlashCategory;
fn handle<'a>(
&'a self,
ctx: &'a mut Ctx,
args: &'a str,
) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>>;
// Provided methods
fn args_hint(&self) -> &'static str { ... }
fn feature_gate(&self) -> Option<&'static str> { ... }
}Expand description
A slash command handler that can be registered with CommandRegistry.
Implementors must be Send + Sync because the registry is constructed at agent
initialization time and handlers may be invoked from async contexts.
§Object safety
The handle method uses Pin<Box<dyn Future>> instead of async fn to remain
object-safe, enabling the registry to store Box<dyn CommandHandler<Ctx>>. Slash
commands are user-initiated so the box allocation is negligible.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Command name including the leading slash, e.g. "/help".
Must be unique per registry. Used as the dispatch key.
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
One-line description shown in /help output.
Sourcefn category(&self) -> SlashCategory
fn category(&self) -> SlashCategory
Category for grouping in /help.
Sourcefn handle<'a>(
&'a self,
ctx: &'a mut Ctx,
args: &'a str,
) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>>
fn handle<'a>( &'a self, ctx: &'a mut Ctx, args: &'a str, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>>
Provided Methods§
Sourcefn args_hint(&self) -> &'static str
fn args_hint(&self) -> &'static str
Argument hint shown after the command name in help, e.g. "[path]".
Return an empty string if the command takes no arguments.
Sourcefn feature_gate(&self) -> Option<&'static str>
fn feature_gate(&self) -> Option<&'static str>
Feature gate label, if this command is conditionally compiled.