https://github.com/znx3p0/io_err
https://github.com/znx3p0/io_err
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/znx3p0/io_err
- Owner: znx3p0
- Created: 2022-05-23T18:58:37.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T19:02:34.000Z (almost 3 years ago)
- Last Synced: 2025-02-09T08:17:10.192Z (3 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# io_err
A serializable version of `std::io::Error` and `std::io::Result` with much better ergonomics.
```rust
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(())
}
```