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:

  1. The original type with any decomposed fields replaced with separate discriminants and payloads.
  2. Getter and setter methods for any decomposed fields. Getters have the same name as the field, setters are prefixed with set_.
  3. Several common trait implementations that are commonly derived: Clone, Debug, Eq, PartialEq.
  4. A ${STRUCT_NAME}Unsplit type with the original enum definition for construction. Convert it into the smaller container from (1) using the decompose() 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:

  1. it is only used on types in “leaf” modules to keep the scope of code reviews small
  2. only code generated by this macro interacts with the discriminant and payload fields