Trait die_exit_2::DieWith

source ·
pub trait DieWith<T, E> {
    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§

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

Implementations on Foreign Types§

Implementors§