https://github.com/printfn/ees
Simple Error-Handling Library
https://github.com/printfn/ees
Last synced: 3 months ago
JSON representation
Simple Error-Handling Library
- Host: GitHub
- URL: https://github.com/printfn/ees
- Owner: printfn
- Created: 2021-05-27T10:49:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-03T22:43:59.000Z (over 3 years ago)
- Last Synced: 2025-01-18T07:12:59.308Z (5 months ago)
- Language: Rust
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.```rust
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(())
}
```