Attribute Macro container
#[container]
Expand description
Apply to a struct to decompose any SplitStorage
enum fields.
Each field must be have the #[split_enum_storage::decomposed]
attribute to have its
discriminant stored out-of-line in the struct. This macro generates:
- The original type with any
decomposed
fields replaced with separate discriminants and payloads. - Getter and setter methods for any
decomposed
fields. Getters have the same name as the field, setters are prefixed withset_
. - Several common trait implementations that are commonly derived: Clone, Debug, Eq, PartialEq.
- A
${STRUCT_NAME}Unsplit
type with the original enum definition for construction. Convert it into the smaller container from (1) using thedecompose()
method.
§Safety
Any field with the #[split_enum_storage::decomposed]
attribute will have its definition
replaced by two private fields: one for the discriminant and one for the payload. These fields
are never made public, but code from the same module sub-tree as the type will be able to
access them.
Until unsafe fields are available, users of this macro should ensure that:
- it is only used on types in “leaf” modules to keep the scope of code reviews small
- only code generated by this macro interacts with the discriminant and payload fields