1 unstable release
0.1.0 | May 23, 2022 |
---|
#2722 in Rust patterns
Used in 3 crates
(via canary)
26KB
452 lines
io_err
A serializable version of std::io::Error
and std::io::Result
with much better ergonomics.
fn test() -> Result<()> {
let res: u32 = may_error()?;
let another: Result<(), &'static str> = Err("error!");
let map_another: Result<()> = another.map_err(err!(@other))?;
err!((other, "error"))?; // == err!(("error"))?;
Ok(())
}
fn return_error() -> Result<()> {
err!(("unknown")) // == Err(err!("unknown"))
}
fn return_error_with_kind() -> Result<()> {
err!((permission_denied, "unknown")) // == Err(err!(permission_denied, "unknown"))
}
fn simple_error() -> Result<()> {
let err: Error = err!("unknown");
Err(err)
}
fn simple_error_with_kind() -> Result<()> {
let err: Error = err!(permission_denied, "unknown");
Err(err)
}
fn errors() -> Result<()> {
let err = "unknown";
bail!("error {:?}", err); // == return err!(("error {:?}", err));
Ok(())
}
fn permission_denied() -> Result<()> {
let err = "denied >:(";
bail!(permission_denied, "error {:?}", err);
Ok(())
}
Dependencies
~0.4–1MB
~22K SLoC