The easiest and most intuitive error handling solution. (no dependencies, about 150 lines pure codes)
| Docs |
First, You should make your own an error set.
rust
err! {
BrokenHeader => "broken header."
AnotherHeader => "not matched header."
FileNotFound => "file not found."
EmptyArgument => "empty argument."
UnexpectedEof => "unexpected eof."
OutOfBounds => "index out of bounds."
NotMatched => "btw not matched."
}
And just errbang!
rust
errbang!(err::BrokenHeader)
```rust
fn foo() -> Result
fn main() -> Result<()> {
let isbar_zero = foo()?;
Ok(())
}
rust
errbang!(err::MyError1);
errbang!(err::MyError2, "cannot find.");
errbang!(err::MyError3, "{} is {}", "bar", 2);
io::Error
```rust
io_err! { // io::ErrorKind => err::MyError UnexpectedEof => err::MyError1 Interrupted => err::MyError2 NotFound => err::MyError3 // ... }
Declare matching macro and just handle that!<br>
rust
iotoerr!(file.seek(SeekFrom::End(0)))?;
errtoio!(my_seek(0))?;
```rust
/// Master Result
pub type Result
rust
pub use utils_results::*;