Expand description
Niche-packing optional: CompactOption<R, T> uses exactly as much memory as
raw R to store either CompactOption::NONE or a Some(T) payload, where T: Copy via the
unsafe CompactRepr contract.
Intended for raw representations R with spare bit patterns. Primary use case:
#[repr(u8)] enums with fewer than 256 variants.
CompactOptionis the safe-ish wrapper API (transmute-based; see docs and Miri).- Implement
CompactReprmanually, or enable themacrosfeature for#[compact_option(repr(R = …, sentinel = …))](see thecompact-option-proc-macrocrate).
Toolchain: this crate pins a nightly toolchain via rust-toolchain.toml and relies on
unstable features.
Structs§
- Compact
Option - Niche-packing optional: stores either
Self::NONEor aSome(T)payload in exactly as much memory as rawR.Tmust beCopy(via theCompactReprcontract); the wrapper itself isCopywheneverRandTare.
Traits§
- Compact
Repr - Safety