Skip to main content

bail

Macro bail 

Source
macro_rules! bail {
    ($msg:literal $(,)?) => { ... };
    ($err:expr $(,)?) => { ... };
    ($fmt:expr, $($arg:tt)*) => { ... };
}
Expand description

Early-returns an error from a handler.

Accepts either a literal/expression convertible into the handler’s error type, or a format!-style format string with arguments.

ⓘ
fn h(_: &mut Engine, args: &[&str]) -> ErrorType {
    if args.is_empty() { bail!("at least one argument required"); }
    let n: u32 = args[0].parse().map_err(|_| format!("bad number: {}", args[0]))?;
    ensure!(n > 0, "must be positive, got {}", n);
    Ok(())
}