Skip to main content

Command

Trait Command 

Source
pub trait Command: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn execute<'a>(
        &'a self,
        ctx: &'a mut BackendContext<'_>,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>;

    // Provided methods
    fn aliases(&self) -> &[&'static str] { ... }
    fn help(&self) -> Option<&'static str> { ... }
    fn matches(&self, msg: &str) -> bool { ... }
}
Expand description

命令 trait,用于实现后端命令

每个命令需要实现此 trait 并注册到 CommandRegistry。

Required Methods§

Source

fn name(&self) -> &'static str

命令名称(不含前导 /)

Source

fn execute<'a>( &'a self, ctx: &'a mut BackendContext<'_>, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>

异步执行命令

返回值:

  • true:消息继续转发给 agent
  • false:命令已处理完毕,不再转发

Provided Methods§

Source

fn aliases(&self) -> &[&'static str]

命令别名(不含前导 /)

Source

fn help(&self) -> Option<&'static str>

命令帮助文本

Source

fn matches(&self, msg: &str) -> bool

检查命令是否匹配给定消息

默认匹配:

  • 精确匹配:/name
  • 带参数:/name ...
  • 别名:/alias/alias ...

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§