Trait die_exit_2::DieWith
source · Expand description
DieWith
is a trait implemented on Result
only to make exiting with messages and codes easy
Required Methods§
sourcefn die_with<X: PrintExit, F: FnOnce(E) -> X>(self, func: F) -> T
fn die_with<X: PrintExit, F: FnOnce(E) -> X>(self, func: F) -> T
Unwraps a Result
, yielding the content of an Ok
.
Exits
Calls process::exit(exit_code) if the value is an Err
, after printing the
message produced by the given function to stderr
.
Examples
Basic usage:
ⓘ
let x: Result<u32, &str> = Err("emergency failure");
x.die_with(|err| format!("strange: {}", err)); // prints `strange: emergency failure` to stderr then exits with code 1
ⓘ
let x: Result<u32, &str> = Err("emergency failure");
x.die_with(|err| (format!("strange: {}", err), 3)); // prints `strange: emergency failure` to stderr then exits with code 3