[][src]Derive Macro embedded_error_chain::ErrorCategory

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

Derive ErrorCategory for an enum.

This will also try to derive the trait dependencies of ErrorCategory with the exception of Copy:

The traits Into<ErrorCode> and From<ErrorCode> are only derived if the enum is repr(u8) (see Data Layout in the nomicon) or does not contain any variants.

Usage

use embedded_error_chain::prelude::*;

#[derive(Clone, Copy, ErrorCategory)]
#[repr(u8)]
enum OtherError {
    ExtremeFailure,
}

static SOME_GLOBAL_VARIABLE: usize = 200;

#[derive(Clone, Copy, ErrorCategory)]
#[error_category(name = "optional name", links(OtherError))]
#[repr(u8)]
enum TestError {
    #[error("format string {summary}, {details}, {variant}, {category}")]
    Foo = 0,

    #[error("custom {}, {:?}", "some_expr", SOME_GLOBAL_VARIABLE)]
    Other,

    /// Summary
    ///
    /// Detailed description.
    /// The summary and detailed description are available as placeholders in
    /// the `#[error(...)]` attribute. If no such attribute is put on the variant
    /// or the `...` part is empty, then the summary will be used. If the summary
    /// does not exist (no doc comments on the variant), then the variant name is
    /// used for debug printing.
    Bar,
}

#[derive(Clone, Copy, ErrorCategory)]
#[error_category(links(OtherError, TestError))]
#[repr(u8)]
enum SeperateError {
    SomethingHappened,
}

#[derive(Clone, Copy, ErrorCategory)]
enum YetEmptyError {}