Crates.io | adhocerr |
lib.rs | adhocerr |
version | 0.1.2 |
source | src |
created_at | 2020-01-08 03:56:17.258588 |
updated_at | 2020-01-17 22:12:27.183409 |
description | A library for the construction of efficient single use static/dynamic error types per callsite. |
homepage | https://github.com/yaahc/adhocerr |
repository | https://github.com/yaahc/adhocerr |
max_upload_size | |
id | 196496 |
size | 17,101 |
A library for the construction of efficient single use static/dynamic error types per callsite.
[dependencies]
adhocerr = "0.1"
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"))
}