Derive Macro Error
#[derive(Error)]
{
// Attributes available to this derive:
#[display]
#[error]
}
Expand description
Derive macro that implements StackError, Display, Debug, std::error::Error,
and generates From<T> impls for fields/variants configured via #[error(..)].
Recognized attributes:
- 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 enum variants and structs:
#[display("..")]: 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(source)]: Sets a field as the source of this error. If a field is namedsourcethis is applied implicitly and not needed.#[error(from)]: Creates aFromimpl for the field’s type to the error type.#[error(std_err)]: Marks the error as astderror. Without this attribute, errors are expected to implementStackError. Only applicable to source fields.