Skip to main content

HandlerFn

Type Alias HandlerFn 

Source
pub type HandlerFn = Arc<dyn for<'a> Fn(&ParsedCommand<'a>) -> Result<(), Box<dyn Error>> + Send + Sync>;
Expand description

A handler function that can be registered on a Command.

The function is stored in an Arc so that Command::clone only increments a reference count rather than copying the closure. The higher-ranked trait bound (for<'a>) allows the handler to be called with a ParsedCommand of any lifetime, which is required because the parsed command borrows from the command tree at call time.

§Examples

let handler: HandlerFn = Arc::new(|parsed| {
    println!("running command: {}", parsed.command.canonical);
    Ok(())
});

Aliased Type§

pub struct HandlerFn { /* private fields */ }