cmdreg 0.1.4

A lightweight string-keyed command dispatcher with axum-style extractors for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use anyhow::Result;

/// A registration entry collected by the `#[command]` macro via `inventory`.
pub struct CommandRegistration {
    pub register: fn() -> Result<()>,
}

inventory::collect!(CommandRegistration);

/// Execute all auto-registered command handlers collected by `#[command]` macros.
pub fn reg_all_commands() -> Result<()> {
    for reg in inventory::iter::<CommandRegistration> {
        (reg.register)()?;
    }
    Ok(())
}