[−][src]Macro symbolic_common::derive_failure
Defines an error type with a failure context and a kind.
The kind enum needs to be defined explicitly, and has to implement Fail
already. This macro
then defines an error type that wraps the kind in a failure::Context
which makes it carry a
backtrace and allows nesting errors, and also defines the following methods on the error type:
kind()
: Returns a reference to the error kind.cause()
: Returns the causing error, if any.backtrace()
: Returns the backtrace of this error (or the cause), ifRUST_BACKTRACE
was set.
In addition to this, the following conversions are defined for the error type:
From<ErrorKind>
From<Context<ErrorKind>>
Example
use failure::Fail; #[derive(Debug, Fail)] enum MyErrorKind { #[fail(display = "some")] Something, #[fail(display = "else")] Else, } derive_failure!(MyError, MyErrorKind); fn something() -> Result<(), MyError> { Err(MyErrorKind::Something.into()) }