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) => { ... };
}Expand description
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,
);