error-rules
Intro
error-rules is a derive macro to implement error handler. Error handler based on the enum. Macro automatically implements conversion of any error type into the inner enum field.
Error conversion
#[error_from]
attribute implements an automatically conversion from any error type.
Converted type should implements std::error::Error
interface.
use *;
type Result<T> = Result;
let error = example.unwrap_err;
assert_eq!;
Custom error kind
#[error_kind]
attribute describes custom error kind.
Could be defined without fields or with fields tuple.
use *;
type Result<T> = Result;
let error = example_1.unwrap_err;
assert_eq!;
let error = example_2.unwrap_err;
assert_eq!;
Display attributes
#[error_from]
and #[error_kind]
contain list of attributes to display error.
First attribute should be literal string. Other attributes is a number of the
unnamed field in the tuple. Started from 0.
#[error_from]
could defined without attributes it's equal to #[error_from("{}", 0)]
Error chain
By implementing error for nested modules the primary error handler returns full chain of the error.
use *;
let error = app_example.unwrap_err;
assert_eq!;