utils-results
The easiest and most intuitive error handling solution. (no dependencies, about 150 lines pure codes)
| Docs | Latest Note |
[]
= "4.2.0"
Overview
First, You should make your own an error set.
err!
And just errbang!
errbang!
More Examples
errbang!;
errbang!;
errbang!;
| Result
[src/main.rs 40:1] unexpected eof. bar is 2 <err::UnexpectedEof>
Important
utils-results can handle lots of errors in a beautiful one way.
It's called Non panic unwraping chaining Errors.
errbang -> errcast -> errcast -> ... -> errcast -> errextract
* Quick Overview
use *;
err!
| Result
Error:
[src/main.rs 11:12] this error is first one. 1.error bang! <err::One> aaa()
⎺↴
[src/main.rs 14:13] this error is second one. 2.two <- one. <err::Two> bbb()
⎺↴
[src/main.rs 18:8] this error is third one. 3.three <- two. <err::Three>
If the matching error be changed,
// Well to Three
let c = errextract!;
| Result
1/127 is cosmological constant.
errcast
Any type of error can be converted into our Master Error. (non panic unwraping)
<Unwraped Ok> = errcast! (<Any Result>, <Master Err>, <Optional meta,..>);
// example
let num_read = errcast!;
Simply just do this!
let file = errcast!
or...
// Master `Result` can take any errors(dyn error)
let file = open?;
But, errcast -> errextract combo is always good choice.
Well, we can also handle io::Error more idiomatic way.
Matching io::Error
io_err!
Declare matching macro and just handle that.
io_to_err!?;
err_to_io!?;
Master Result
- Please use our Master Result<T> and ResultSend<T> instead std::result::Result or io::Result etc..
utils-results/lib.rs Definition
/// Master Result
pub type Result<T> = Result;
/// Master Result for Send + Sync trait
pub type ResultSend<T> = Result;
just put this in your project.
pub use *;
You can also convert any type of Result
| easy way
// to our Master Result
resultcast!?;
// to our Master ResultSend
resultcastsend!?;