[][src]Macro failchain::ensure

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

Returns early with an error built from an error kind if a given condition is false.

Examples

// With an ErrorKind.
ensure!(
    file_path != corrupt_file_path,
    ErrorKind::CorruptFile(format!("the file at {:?} is corrupt", file_path))
);

// With an ErrorKind and format string (equivalent ot the above.)
ensure!(
    file_path != corrupt_file_path,
    ErrorKind::CorruptFile,
    "the file at {:?} is corrupt",
    file_path,
);