Crate ees[][src]

Expand description

This library is intended to provide simple error-handling-related helper functions and types. Rather than provide its own error-related types, it is centered around the std::error::Error type.

Usage:

use std::io::Read;

// Use ees::Error for arbitrary owned errors
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 with a given message
        ees::bail!("file is empty");
    }
    Ok(())
}

// ees::ErrorRef<'_> represents 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()?;
    Ok(())
}

Macros

bail

Construct an error on the fly, and immediately return from the current function

err

Construct an error on the fly

Structs

MainError

This type wraps an arbitrary error, and is intended for use in the main() method

Functions

add_message

Wrap the given error in a new error, with the given error message

error_with_message

Create a new error with a given message

print_error_chain

Print the complete error chain of an error, separated with colons

Type Definitions

Error

Represents an arbitrary owned error

ErrorRef

Represents an arbitrary borrowed error with a given lifetime

MainResult

A convenient way to return arbitrary errors from main()