utils-results
The easiest and most intuitive error handling solution.
| Docs | Latest Note |
[]
= "5.3.0"
No-std
Disable default feature(allocator is needed).
[]
= { = "5.3.0", = false }
Overview
First, You should make your own an error set.
err!
And just errbang!
errbang!
More Examples
errbang!;
errbang!;
errbang!;
errbang!;
| Result
[src/main.rs 40:1] unexpected eof. bar is 2 <err::UnexpectedEof>
unwrapping error input data. also can easily compare them.
assert_eq!;
Important
-
- One result type(
anyhow
).
- One result type(
-
- All casted errors have their own chaining error' information(all the previous errors).
if you follow below rules, you can easily debug all your projects.
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 has 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
let file = open?;
// if cfg!(no_std),
let file = io_to_err!?;
But, errcast -> errextract combo is always good choice.
Well, we can also handle io::Error more idiomatic way. (feature = "std")
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> instead std::result::Result or io::Result etc..
- this is
anyhow
Result.
utils-results/lib.rs Definition
/// Master Result
pub type Result<T> = Result;
just put this in your project.
pub use *;
You can also convert any type of Result
// to our Master Result
resultcast!?;