[][src]Derive Macro erroneous_derive::Error

#[derive(Error)]
{
    // Attributes available to this derive:
    #[error]
}

Derive std::error::Error for the struct or enum, and ascertain that it is Send, Sync, 'static, and thus also erroneous::Error.

You can declare a field in each variant (only one variant if a struct) of your type, which is to be the result of the std::error::Error::source method. You simply attach the attribute #[error(source)] or #[error(defer)] to the field. The first one does the obvious thing and just returns a reference to the field. The second one makes it return the result of the field's implementation of the source method. This is occasionally useful to avoid duplication of error messages when iterating the chain of errors.

Example:

This example is not tested
#[derive(Error)]
pub enum MyError {
    A(#[error(source)] A),
    B(#[error(defer)] B),
    C(C),
}