Macro simple_error::bail [] [src]

macro_rules! bail {
    ($e:expr) => { ... };
    ($fmt:expr, $($arg:tt)+) => { ... };
}

Helper macro for returning a SimpleError constructed from either a Into<SimpleError>, a string slice, or a formatted string.

Examples

use self::simple_error::SimpleError;
// Use with a `Into<SimpleError>`

struct ErrorSeed;

impl From<ErrorSeed> for SimpleError {
    fn from(_: ErrorSeed) -> SimpleError {
        SimpleError::new(".")
    }
}

fn bail_block_into(es: ErrorSeed) -> Result<(), SimpleError> {
    bail!(es);
}

// Use with a string slice
fn bail_block_str(s: &str) -> Result<(), SimpleError> {
    bail!(s);
}

// Use with a formatted string
fn bail_block_format(s: &str) -> Result<(), SimpleError> {
    bail!("reason: {}", s);
}