Macro uucore::crash_if_err
source · macro_rules! crash_if_err { ($exit_code:expr, $exp:expr) => { ... }; }
Expand description
Unwrap a std::result::Result
, crashing instead of panicking.
If the result is an Ok
-variant, returns the value contained inside. If it
is an Err
-variant, invokes crash!
with the formatted error instead.
Examples
ⓘ
let is_ok: Result<u32, &str> = Ok(1);
// Does nothing
crash_if_err!(1, is_ok);
let is_err: Result<u32, &str> = Err("This didn't work...");
// Calls `crash!`
crash_if_err!(1, is_err);