Skip to main content

Crate compact_option

Crate compact_option 

Source
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.

  • CompactOption is the safe-ish wrapper API (transmute-based; see docs and Miri).
  • Implement CompactRepr manually, or enable the macros feature for #[compact_option(repr(R = …, sentinel = …))] (see the compact-option-proc-macro crate).

Toolchain: this crate pins a nightly toolchain via rust-toolchain.toml and relies on unstable features.

Structs§

CompactOption
Niche-packing optional: stores either Self::NONE or a Some(T) payload in exactly as much memory as raw R. T must be Copy (via the CompactRepr contract); the wrapper itself is Copy whenever R and T are.

Traits§

CompactRepr
Safety