Struct attributes
The following attributes may be used in a superstruct
macro invocation on a
struct
item. All attributes are optional unless stated otherwise.
Variants
#[superstruct(variants(A, B, ...))]
Define the list of variants that this type has. See variant structs.
The variants
attribute is not optional.
Format: 1+ comma-separated identifiers.
Cast error
#[superstruct(cast_error(ty = "..", expr = ".."))]
Define the error type to be returned from casting methods.
The expression must be of the given error type, and capable of being evaluated without any context (it is not a closure).
Format: quoted type for ty
, quoted expression for expr
Partial getter error
#[superstruct(cast_error(ty = "..", expr = ".."))]
Define the error type to be returned from partial getter methods.
The expression must be of the given error type, and capable of being evaluated without any context (it is not a closure).
Format: quoted type for ty
, quoted expression for expr
Variant attributes
#[superstruct(variant_attributes(...))]
Provide a list of attributes to be applied verbatim to each variant struct definition.
This can be used to derive traits, perform conditional compilation, etc.
Format: any.
Specific variant attributes
#[superstruct(specific_variant_attributes(A(...), B(...), ...))]
Similar to variant_attributes
, but applies the attributes only to the named variants. This
is useful if e.g. one variant needs to derive a trait which the others cannot, or if another
procedural macro is being invoked on the variant struct which requires different parameters.
Format: zero or more variant names, with variant attributes nested in parens
Ref
attributes
#[superstruct(ref_attributes(...))]
Provide a list of attributes to be applied verbatim to the generated Ref
type.
Format: any.
RefMut
attributes
#[superstruct(ref_mut_attributes(...))]
Provide a list of attributes to be applied verbatim to the generated RefMut
type.
Format: any.
No enum
#[superstruct(no_enum)]
Disable generation of the top-level enum, and all code except the variant structs.
Map Into
#[map_into(ty1, ty2, ..)]
#[map_ref_into(ty1, ty2, ..)]
#[map_ref_mut_into(ty1, ty2, ..)]
Generate mapping macros from the top-level enum, the Ref
type or the RefMut
type as appropriate.
Please see the documentation on Mapping into other types for an explanation of how these macros operate.
Format: one or more superstruct
type names
Meta variants
#[superstruct(meta_variants(A, B, ...), variants(C, D, ...))]
Generate a two-dimensional superstruct. See meta variant structs.
The meta_variants
attribute is optional.
Format: 1+ comma-separated identifiers.