Crates.io | orfail |
lib.rs | orfail |
version | 1.1.0 |
source | src |
created_at | 2022-10-25 10:04:01.221047 |
updated_at | 2023-08-18 11:01:38.204982 |
description | Error handling library for portable unrecoverable errors |
homepage | https://github.com/sile/orfail |
repository | https://github.com/sile/orfail |
max_upload_size | |
id | 696763 |
size | 24,411 |
An error handling library for portable unrecoverable errors.
This crate provides,
Failure
struct that represents an unrecoverable error with an error message and user-level backtrace
u32
, String
, and Vec
of those)
serde
support ("serde" feature)std::error::Error
traitOrFail
trait
Failure
each time when calling OrFail::or_fail()
bool
, Option<_>
and Result<_, _>
implement OrFail
use orfail::{OrFail, Result};
fn check_non_zero(n: isize) -> Result<()> {
(n != 0).or_fail()?;
Ok(())
}
fn safe_div(x: isize, y: isize) -> Result<isize> {
check_non_zero(y).or_fail()?;
Ok(x / y)
}
// OK
assert_eq!(safe_div(4, 2), Ok(2));
// NG
assert_eq!(safe_div(4, 0).err().map(|e| e.to_string()),
Some(
r#"expected `true` but got `false`
at src/lib.rs:8
at src/lib.rs:13
"#.to_owned()));