Trait die_exit::Die

source ·
pub trait Die<T> {
    // Required methods
    fn die(self, msg: &str) -> T;
    fn die_code(self, msg: &str, exit_code: i32) -> T;
}
Expand description

Die is a trait implemented on Result and Option to make exiting with messages and codes easy

Required Methods§

source

fn die(self, msg: &str) -> T

Unwraps a Result or Option, yielding the content of an Ok or Some.

§Exits

Calls process::exit(1) if the value is an Err or None, after printing the passed message to stderr.

§Examples

Basic usage:

let x: Result<u32, &str> = Err("emergency failure");
x.die("strange error"); // prints `strange error` to stderr then exits with code 1
let x: Option<u32> = None;
x.die("strange error"); // prints `strange error` to stderr then exits with code 1
source

fn die_code(self, msg: &str, exit_code: i32) -> T

Unwraps a Result or Option, yielding the content of an Ok or Some.

§Exits

Calls process::exit(exit_code) if the value is an Err or None, after printing the passed message to stderr.

§Examples

Basic usage:

let x: Result<u32, &str> = Err("emergency failure");
x.die_code("strange", 3); // prints `strange` to stderr then exits with code 3
let x: Option<u32> = None;
x.die_code("strange", 3); // prints `strange` to stderr then exits with code 3

Implementations on Foreign Types§

source§

impl<T> Die<T> for Option<T>

source§

fn die(self, msg: &str) -> T

source§

fn die_code(self, msg: &str, exit_code: i32) -> T

source§

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

source§

fn die(self, msg: &str) -> T

source§

fn die_code(self, msg: &str, exit_code: i32) -> T

Implementors§