pub trait Command:
Send
+ Sync
+ 'static {
type Request: DeserializeOwned + Send + 'static;
type Response: Serialize + Send + 'static;
const ID: &'static str;
const DESCRIPTION: Option<&'static str> = None;
// Required method
fn handle(
&self,
request: Self::Request,
) -> impl Future<Output = Result<Self::Response, CommandError>> + Send;
// Provided methods
fn id(&self) -> &str { ... }
fn description(&self) -> Option<&str> { ... }
fn schema(&self) -> Option<CommandSchema> { ... }
}Expand description
A typed command handler registered with a
CommandRegistry.
Implementations are zero-cost at registration time: the registry
wraps the typed handler in a dynamically-dispatched closure that
decodes the incoming request JSON into Request,
runs handle, and re-encodes the result.
§Compile-time vs runtime commands
- Compile-time:
const ID/const DESCRIPTIONand the#[command]macro. The defaults foridanddescriptionread these constants. - Runtime: use
DynCommandto supply an ownedStringid, description, and schema.DynCommandimplementsCommandby overriding the instance-level methods.
Both paths register through the same
register_command
entry point.
Required Associated Constants§
Sourceconst ID: &'static str
const ID: &'static str
Compile-time identifier for typed commands. Ignored when a
command overrides id to return a runtime string
(as DynCommand does).
Identifiers prefixed with _ are treated as private: they are
never escalated to a router channel and never advertised to
peers via list.commands.response.
Provided Associated Constants§
Sourceconst DESCRIPTION: Option<&'static str> = None
const DESCRIPTION: Option<&'static str> = None
Optional compile-time description. Ignored when
description is overridden.
Required Associated Types§
type Request: DeserializeOwned + Send + 'static
type Response: Serialize + Send + 'static
Required Methods§
Provided Methods§
Sourcefn id(&self) -> &str
fn id(&self) -> &str
Instance-level identifier. Defaults to ID.
DynCommand overrides this to return a runtime-owned id.
Sourcefn description(&self) -> Option<&str>
fn description(&self) -> Option<&str>
Instance-level description. Defaults to
DESCRIPTION.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.