pub trait Handler {
type Output: Serialize;
// Required method
fn handle(
&mut self,
matches: &ArgMatches,
ctx: &CommandContext,
) -> HandlerResult<Self::Output>;
}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.