Der Fehler is a small but very opinionated Rust error handling library.
In many ways, der Fehler is a successor to failure. However, unlike failure,
der Fehler is built around the standard library's
Error trait, which has
adopted the necessary improvements that the
Fail trait had provided thanks to
Der Fehler provocatively and unapologetically uses the terminology of exceptions.
Der Fehler provides these items:
Exception is a polymorphic error type, essentially a trait object. It is
similar to the
failure::Error type, but for the
Error trait in std. There
are a few key improvements:
failure::Erroris possible to construct an ad hoc error from any type that implements
Display(such as a string). Unlike
failure::Error, it can be properly downcast to that type.
Exceptionis guaranteed to be the size of a single narrow pointer (
failure::Erroris the size of a wide pointer).
Otherwise, it is roughly the same type: an Error trait object that guarantees the presence of a backtrace.
throw! is a macro which is equivalent to the
Err($e)? pattern. It takes an
error type and "throws" it.
The throws attribute modifies a function or method to make it return a
Result. It takes an optional typename as an argument to the attribute which
will be the error type of this function; if no typename is supplied, the error
Within the function body,
returns (including the implicit final return) are
automatically "Ok-wrapped." To raise errors, use
? or the
For example, these two functions are equivalent:
This macro constructs an ad hoc error from format strings, similar to the
This crate also defines a
Context trait for the
Result type, which
context method for injecting context around an error.
- Possibly add a Display derive
- Make throws work on closures and async blocks (attributes are not allowed on expressions on stable)
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.