Exun
There are many errors we don't expect to occur. But what if we're wrong? We don't want our programs to panic because of that. We also don't want to spend so much time handling unexpected errors. That's what this crate is for. You keep your unexpected errors, and don't worry about them until later.
-
This crate works in
no-std. Some extra features come ifallocorstdis used. -
Exunis an error type. It'll hold on to yourUnexpectederror if you have one, so you can figure out what to do with it later. If the error isExpected, then it'll hold onto that too. -
RawUnexpectedbottles up all of your unexpected errors. There's alsoUnexpectedError, which implementsError. -
Expectis a type alias forExun<E, RawUnexpected>. -
Clearly mark errors that you don't expect to occur by calling
Result::unexpect. If the error type doesn't implementError, you can still useResult::unexpect_msg, as long as it implementsDebug + Display + Send + Sync + 'static.
Usage
The only pre-requisite is Rust 1.41.1.
For standard features:
[]
# ...
= "0.2"
The following features are enabled by default:
-
std: This automatically enablesalloc. It's used for the standard library'sErrortype. Using this type allows more errors to be converted intoExunandRawUnexpectederrors automatically, and it's needed forResult::unexpect. -
alloc: This is needed forRawUnexpectedandUnexpectedErrorto hold string messages. This can be done withResult::unexpect_mshg. Without this, only the equivalent ofResult::unexpect_nonecan be constructed.
To disable these features:
[]
# ...
= { = "0.2", = false }
If you'd like to use alloc but not std:
[]
# ...
= { = "0.2", = false, = ["alloc"] }
Examples
use *;
use *;
use Error;
use ;
use *;
;
use Error;
use ;
use ParseIntError;
use *;
;