Trait die_exit::DieWith

source ·
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§

source

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T, E> DieWith<T, E> for Result<T, E>

source§

fn die_with<X: PrintExit, F: FnOnce(E) -> X>(self, func: F) -> T

Implementors§