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> { ... }
fn requires_auth(&self) -> bool { ... }
}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.
Sourcefn requires_auth(&self) -> bool
fn requires_auth(&self) -> bool
Returns true if this command requires a trusted (local) caller.
When true, CommandRegistry::dispatch rejects the command with an authorization
error if the dispatch site passes trusted = false.
The default returns true (fail-closed): a handler that does not override this
method requires a trusted session. Read-only or self-gated commands that are safe
to expose on remote channels (Telegram, Discord, Slack) must explicitly opt out by
overriding this to return false.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".