n0_error

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)]: Creates From impls for the source types 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, _1 etc.
    • #[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 named source this is applied implicitly and not needed.
    • #[error(from)]: Creates a From impl for the field’s type to the error type.
    • #[error(std_err)]: Marks the error as a std error. Without this attribute, errors are expected to implement StackError. Only applicable to source fields.