#error #construction #single #per #type #callsite #static-dynamic

adhocerr

A library for the construction of efficient single use static/dynamic error types per callsite

3 releases

0.1.2 Jan 17, 2020
0.1.1 Jan 8, 2020
0.1.0 Jan 8, 2020

#1547 in Rust patterns

Download history 48/week @ 2024-02-19 10/week @ 2024-02-26 4/week @ 2024-03-04

62 downloads per month

MIT/Apache

18KB
162 lines

Adhoc Errors

Latest Version Rust Documentation

A library for the construction of efficient single use static/dynamic error types per callsite.

[dependencies]
adhocerr = "0.1"

Examples

Creating a root cause error:

use adhocerr::err;

fn get_git_root(start: &Path) -> Result<PathBuf, impl Error + 'static> {
    start
        .ancestors()
        .find(|a| a.join(".git").is_dir())
        .map(Path::to_owned)
        .ok_or(err!("Unable to find .git/ in parent directories"))
}

Wrapping another Error:

use adhocerr::wrap;

fn record_success() -> Result<(), impl Error + 'static> {
    std::fs::write(".success", "true").map_err(wrap!("Failed to save results of script"))
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps