pub trait Handler {
type Output: Serialize;
// Required method
fn handle(
&mut self,
matches: &ArgMatches,
ctx: &CommandContext,
) -> HandlerResult<Self::Output>;
// Provided method
fn expected_args(&self) -> Vec<ExpectedArg> { ... }
}Expand description
Trait for command handlers.
Handlers take &mut self allowing direct mutation of internal state.
This is the common case for CLI applications which are single-threaded.
§Example
use standout_dispatch::{Handler, HandlerResult, Output, CommandContext};
use clap::ArgMatches;
use serde::Serialize;
struct Counter { count: u32 }
impl Handler for Counter {
type Output = u32;
fn handle(&mut self, _m: &ArgMatches, _ctx: &CommandContext) -> HandlerResult<u32> {
self.count += 1;
Ok(Output::Render(self.count))
}
}Required Associated Types§
Required Methods§
Sourcefn handle(
&mut self,
matches: &ArgMatches,
ctx: &CommandContext,
) -> HandlerResult<Self::Output>
fn handle( &mut self, matches: &ArgMatches, ctx: &CommandContext, ) -> HandlerResult<Self::Output>
Execute the handler with the given matches and context.
Provided Methods§
Sourcefn expected_args(&self) -> Vec<ExpectedArg>
fn expected_args(&self) -> Vec<ExpectedArg>
Returns the arguments expected by this handler for verification.
This is used to verify that the CLI command definition matches the handler’s expectations.
Handlers generated by the #[handler] macro implement this automatically.