Crates.io | exitfailure |
lib.rs | exitfailure |
version | 0.5.1 |
source | src |
created_at | 2018-05-13 10:38:36.383009 |
updated_at | 2018-08-03 09:21:17.360309 |
description | A basic newtype wrappers for use with ? in main |
homepage | |
repository | https://github.com/tismith/exitfailure |
max_upload_size | |
id | 65170 |
size | 33,248 |
exitfailure
provides some newtype wrappers to help with using ? in main()
.
It is intended to be used with rust 1.26 and above's "? in main()" feature (see the tracking issue here).
The primary items exported by this library are:
ExitFailure
: a wrapper around failure::Error
to allow ? printing from main
to present a nicer error message, including any available context and backtrace.
ExitDisplay<E>
: a wrapper around E: std::fmt::Display
to allow the error message
from main to use Display
and not Debug
.
For more information, including more details on the types, please see the API Documentation.
Example:
#[macro use] extern crate failure;
extern crate exitfailure;
use failure::ResultExt;
use exitfailure::ExitFailure;
fn main() -> Result<(), ExitFailure> {
Ok(some_fn()?)
}
fn some_fn() -> Result<(), failure::Error> {
let error = Err(failure::err_msg("root cause failure"));
Ok(error.context("this is some context".to_string())?)
}
This will print, when executed:
Error: this is some context
Info: caused by root cause failure
If the environment variable RUST_BACKTRACE=1 is set, then the printing will
include whatever backtrace information is provided by the failure::Error
that is being wrapped.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.