adhocerr 0.1.2

A library for the construction of efficient single use static/dynamic error types per callsite.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented6 out of 6 items with examples
  • Size
  • Source code size: 17.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.43 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • yaahc/adhocerr
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yaahc

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