Crate split_enum_storage

Source
Expand description

Library to allow storing enum discriminants out-of-line from payloads without maintaining unsafe code. Makes structs smaller when they have enum fields whose discriminants are stored with padding in the enum layout due to payload alignment requirements.

An enum’s internal padding can result in a lot of memory used even when the use case does not require the ability to return a concrete reference to the enum type. This macro allows relaxing the requirement at the expense of ergonomics, storing enum discriminants in bytes of a struct that would otherwise be used by the compiler for padding. Callers then interact with the enum “field” through generated accessors.

Traits§

SplitStorage
A trait for enums which can be decomposed into a separate discriminant and data payload.

Attribute Macros§

container
Apply to a struct to decompose any SplitStorage enum fields.

Derive Macros§

SplitStorage
Derive the SplitStorage trait for an enum so that its discriminant and payload can be stored separately. Structs which store such enums can use the #[split_enum_storage::container] macro to take advantage of the generated trait implementation.