rust-errkit 0.1.0

Idiomatic Rust error handling kit
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use rust_errkit::{AppError, AppResult, ResultExt, kind::ErrorKind};

fn might_fail(success: bool) -> Result<String, &'static str> {
    if success {
        Ok("OK".to_string())
    } else {
        Err("something went wrong")
    }
}

fn main() -> AppResult<()> {
    let value = might_fail(false).map_err(|e| {
        AppError::from(ErrorKind::unknown()).with_context("might_fail", Some(e.to_string()))
    })?;

    println!("{}", value);
    Ok(())
}