#[derive(StackError)]
{
// Attributes available to this derive:
#[error]
}
Expand description
Derive macro that implements StackError, Display, Debug and std::error::Error
and generates From<T> impls for fields/variants configured via #[error(..)].
Derive macro for stack errors.
This derive macro can be applied to structs and enums. Unit, tuple and named-field variants are supported equally.
The macro will expand to implementations of StackError, Display, Debug and Error.
It will also add From impls for fields configured via the error attribute.
Items with the derive macro applied accept an #[error(args)] attribute, where args is a comma-separated
list of arguments. The supported arguments vary by on the kind of item:
- on enums:
#[error(from_sources)]: CreatesFromimpls for thesourcetypes of all variants. Will fail to compile if multiple sources have the same type.#[error(std_sources)]: Defaults all sources to be std errors instead of stack errors.
- on structs and enum variants:
#[error("format {field}: {}", a + b)]: Sets the display formatting. You can refer to named fields by their names, and to tuple fields by_0,_1etc.#[error(transparent)]: Directly forwards the display implementation to the error source, and omits the outer error in the source chain when reporting errors.
- on fields:
#[error(from)]: Creates aFromimpl for the field’s type to the error type.#[error(source)]: The error’ssourcemethod returns a reference to whatever field is namedsource, or has thesourceattribute set.#[error(std_err)]: Only on onsourcefields. Marks the error as astderror. Source fields not marked asstd_errneed to implementStackError.#[error(stack_error)]: Only onsourcefields. Marks the error as aStackError. This is the default unlessstd_sourcesis set on the top-level item.#[error(meta)]: Sets a field as themetafield for this error or variant. Must have type [::n0_error::Error`]