14 releases (1 stable)

1.0.0 Mar 3, 2022
0.2.5 Jun 5, 2021
0.2.0 May 27, 2021
0.1.6 May 27, 2021

#473 in Rust patterns

Download history 60/week @ 2022-06-07 4/week @ 2022-06-14 10/week @ 2022-06-21 18/week @ 2022-06-28 32/week @ 2022-07-05 32/week @ 2022-07-12 18/week @ 2022-07-19 33/week @ 2022-07-26 50/week @ 2022-08-02 14/week @ 2022-08-09 6/week @ 2022-08-16 25/week @ 2022-08-23 9/week @ 2022-08-30 40/week @ 2022-09-06 35/week @ 2022-09-13 7/week @ 2022-09-20

93 downloads per month
Used in 4 crates

CC0 license

13KB
284 lines

ees: Simple Error-Handling Library

ees is a simple error-handling library. Rather than provide its own error-related types, it uses std::error::Error and provides a number of convenience functions.

use std::io::Read;

// Use ees::Error for arbitrary owned errors
// You can also use ees::Result<()> as a shorthand
fn do_work() -> Result<(), ees::Error> {
    let mut file = std::fs::File::open("hello world")?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
    if contents.is_empty() {
        // Construct an error on the fly
        ees::bail!("file is empty");
    }
    Ok(())
}

// Take an arbitrary borrowed error
fn take_an_error(error: ees::ErrorRef<'_>) {
    // Print the complete error chain
    println!("Error: {}", ees::print_error_chain(error));
}

// Use ees::MainResult to automatically create nicely-
// formatted error messages in the main() function
fn main() -> ees::MainResult {
    do_work()?;
    do_work().map_err(
        // add additional context
        |e| ees::wrap!(e, "failed to do work"))?;
    Ok(())
}

No runtime deps