#[derive(Error)]
{
// Attributes available to this derive:
#[derail]
}
Expand description
Generates an implementation of derail::Error and Display.
This macro can be applied to structs and enums. Unless otherwise noted, each
struct and enum variant will be observed by a derail::Visitor, followed by
its children if it has any.
§Options
This derive macro accepts attributes of the form #[derail(..., ..., ...)],
where each ... is an option. At least one option is required per attribute.
Trailing commas are optional. Descriptions of each option follow.
§child
- Applicable to:
structfields,enumvariant fields. - Optional.
- Conflicts with:
children,skip_child,skip_self.
This option causes derail::Error::accept to be generated such that the field
is visited as a single child. The field must be a derail::Error. For structs
and enum variants with named fields, set the name of the field to child
rather than using this attribute.
§children
- Applicable to:
structfields,enumvariant fields. - Optional.
- Conflicts with:
child,skip_child,skip_self.
This option causes derail::Error::accept to be generated such that the field
is visited as a group of children. The field must be an ExactSizeIterator
that yields derail::Errors. For structs and enum variants with named
fields, set the name of the field to children rather than using this
attribute.
§skip_child
- Applicable to:
structfields,enumvariant fields. - Optional.
- Conflicts with:
child,children,skip_self.
This option causes derail::Error::accept to be generated such that the field’s
children are visited, but the field itself is skipped. The field must be a
derail::Error. For structs and enum variants with named fields, set the
name of the field to skip_child rather than using this attribute.
§skip_self
- Applicable to:
structfields,enumvariant fields. - Optional.
- Conflicts with:
child,children,skip_child,display(...).
This option causes derail::Error::accept to be generated such that the struct
or enum variant containing this field is skipped, and the field is visited
directly. It also causes Display::fmt to be generated for this struct
or enum variant such that the field’s implementation of Display::fmt is
called directly. The field must be a derail::Error. For structs and enum
variants with named fields, set the name of the field to skip_self rather than
using this attribute.
§map_details = ...
- Applicable to:
structfields,enumvariant fields; only where the chosen field also has one of thechild,children,skip_child, orskip_selfoptions set. - Required if the parent and child have different concrete types for
derail::Error::Details.
This option causes derail::Error::accept (and derail::Error::details in the
case of skip_self) to be generated such that the function provided in place of
... is used to map the child’s derail::Error::Details into the parent’s. If
= ... is omitted, From::from will be used.
This is primarily useful for enabling a derail::Error to contain child
derail::Errors where the parent and children have different concrete types for
derail::Error::Details. Where an identity function would be provided in place
of ..., simply omit this option instead.
§display(...)
- Applicable to:
structs,enumvariants. - Required unless
skip_selfis used. - Conflicts with:
skip_self.
This option causes Display::fmt to be generated such that the tokens
provided in place of ... are provided to write after $dst. Fields of
structs and enum variants with named fields can be referred to by the same
identifier. Fields of structs and enum variants with unnamed fields can be
referred to by an identifier made by prefixing their index with an underscore.
See also the rules for implementing Display::fmt for Error
implementors.
§details
- Applicable to:
structfields,enumvariant fields. - Required if
derail::Error::Detailsis not().
This option chooses the field to return when derail::Error::details is called.
For structs and enum variants with named fields, set the name of the field
to details rather than using this attribute.
§details = ...
- Applicable to:
structs,enumvariants. - Required if
derail::Error::Detailsis not()and there is no field nameddetailsor decorated with#[derail(details)].
This option causes derail::Error::details to be generated such that the
expression provided in place of ... is evaluated and returned. Like with
display(...), the expression can access named fields of the struct or enum
variant using the same identifier, and unnamed fields using the index prefixed
with an underscore.
§type Details = ...
- Applicable to:
structs,enums. - Required.
This option sets the type to use for the derail::Error::Details associated
type in the generated derail::Error implementation.
§impl<...> Error where { ... }
- Applicable to:
structs,enums. - Optional.
This option allows for the generated derail::Error implementation to have
its impl generics extended and its where clause set. Any generic parameters
on the struct or enum definition will already be present in the generated
impl generics. The <...> portion can be used to extend the set of impl
generics (with or without predicates) and may be omitted if doing so is not
required. Comma-separated where clause predicates can be specified within the
curly brackets. No predicates will be automatically inferred from the struct
or enum definition.
§impl<...> Display where { ... }
- Applicable to:
structs,enums. - Optional.
This option allows for the generated Display implementation to have its
impl generics extended and its where clause set. Any generic parameters
on the struct or enum definition will already be present in the generated
impl generics. The <...> portion can be used to extend the set of impl
generics (with or without predicates) and may be omitted if doing so is not
required. Comma-separated where clause predicates can be specified within the
curly brackets. No predicates will be automatically inferred from the struct
or enum definition.
§crate = ...
- Applicable to:
structs,enums. - Optional.
This option can be used to change the path to the root of the derail crate
used in macro expansion.