Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "exitfailure"
version = "0.5.1"
version = "0.6.0"
authors = ["Toby Smith <toby@tismith.id.au>"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/tismith/exitfailure"
description = "A basic newtype wrappers for use with ? in main"
description = "Types to help with using ? in main"
categories = ["command-line-interface"]
keywords = ["newtype", "failure", "error", "command-line", "cli"]

Expand Down
3 changes: 1 addition & 2 deletions examples/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
extern crate exitfailure;
extern crate failure;

use exitfailure::ExitFailure;
use failure::ResultExt;

fn main() -> Result<(), ExitFailure> {
fn main() -> exitfailure::Result {
let error = Err(failure::err_msg("root cause failure"));
Ok(error.context("this is some context".to_string())?)
}
3 changes: 1 addition & 2 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
extern crate exitfailure;
extern crate failure;

use exitfailure::ExitFailure;
use failure::ResultExt;

fn main() -> Result<(), ExitFailure> {
fn main() -> exitfailure::Result {
Ok(some_fn()?)
}

Expand Down
32 changes: 28 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,45 @@
variant_size_differences
)]

//! Some newtype wrappers to help with using ? in main()
//! Some newtype wrappers to help with using ? in `main`
//!
//! 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.
//! - `Result`: a type alias around `std::result::Result<(), exitfailure::ExitFailure>` to be used
//! in the return position from `main`. To make your program simpler and give nice error
//! messages, just make your main function return this, e.g. `fn main() -> exitfailure::Result`
//!
//! - `ExitFailure`: a wrapper around `failure::Error` to allow ? printing from `main`
//! to present a nicer error message, including any available context and backtrace. It's
//! better to use the `Result` type alias instead of using this directly.
//!
//! - `ExitDisplay<E>`: a wrapper around `E: std::fmt::Display` to allow the error message
//! from main to use `Display` and not `Debug`
//! from main to use `Display` and not `Debug`. Use this if the functions you're using `?` with
//! are returning some non-`Error` type that implements `Display` that you want to use for
//! user-visible error messages (such as `String`).
//!
//! Basically, these types should only ever be used in the return type for
//! `main()`
//!
extern crate failure;

/// A helping type alias around `std::result::Result<(), exitfailure::ExitFailure>`
///
/// ```rust,should_panic
/// # extern crate failure;
/// # extern crate exitfailure;
/// # use failure::ResultExt;
/// fn main() -> exitfailure::Result {
/// 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())?)
/// }
/// ```
pub type Result = std::result::Result<(), ExitFailure>;

/// The newtype wrapper around `failure::Error`
///
/// ```rust,should_panic
Expand Down