pub trait DieWith<T, E> {
// Required method
fn die_with<X: PrintExit, F: FnOnce(E) -> X>(self, func: F) -> T;
}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 1let 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 3Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.