Skip to main content

command

Attribute Macro command 

Source
#[command]
Expand description

Attach to an async fn (free-standing or inside a #[command_service] impl block) to register it as a typed command.

Usage inside a #[command_service] impl Service block:

#[command_service]
impl Service {
    #[command("math.add", description = "Add two numbers")]
    async fn add(&self, req: AddReq) -> Result<i64, CommandError> { ... }
}

Usage as a free function:

#[command("greet")]
async fn greet(name: String) -> Result<String, CommandError> { ... }
// Exposes `register_greet(&registry).await?` to install the command.