Skip to main content

Command

Trait Command 

Source
pub trait Command: Send + Sync {
    // Required methods
    fn signature(&self) -> CommandSignature;
    fn execute(&self, args: &[String]) -> Result<i32, CliError>;
}
Expand description

自定义控制台命令 trait

对齐 PHP think\console\Command 抽象基类。

PHP 端通过继承 Command 并实现 configure()execute() 方法定义命令; Rust 端通过实现此 trait 达到相同效果。

Required Methods§

Source

fn signature(&self) -> CommandSignature

获取命令签名

对齐 PHP think\console\Command::configure()

Source

fn execute(&self, args: &[String]) -> Result<i32, CliError>

执行命令

对齐 PHP think\console\Command::execute(Input $input, Output $output)

§参数
  • args:命令参数(不含程序名与命令名,仅含命令后的额外参数)
§返回
  • Ok(0):成功
  • Ok(code):命令指定的退出码(非 0 表示部分失败)
  • Err(_):内部错误

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§