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 trait.
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 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( |e| ees::wrap!(e, "failed to 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 |
wrap | Wrap an error in a new on-the-fly error |
Structs
MainError | This type wraps an arbitrary error, and is intended for use in the |
Functions
print_error_chain | Print the complete error chain of an error, separated with colons |
to_err | Convert any error into a type that implements std::error::Error. This
is mainly useful for converting Error types to |
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 |