4 ms·
References only have a single bit available as a niche (the null byte), which Option makes use of for null pointer optimization (https://doc.rust-lang.org/std/o
by timClicks 10mo ago
References only have a single bit available as a niche (the null byte), which Option makes use of for null pointer optimization (https://doc.rust-lang.org/std/option/index.html#representation https://doc.rust-lang.org/std/option/index.html#representati...).
In principle, you Rust could create something like std::num::NonZero and its corresponding sealed trait ZeroablePrimitive to mark that two bits are unused. But that doesn't exist yet as far as I know.
- Rusky 10mo agoThere are also currently the unstable rustc_layout_scalar_valid_range_start and rustc_layout_scalar_valid_range_end attributes (which are used in the definition of NonNull, etc.) which could be used for some bit patterns. Also aspirations to use pattern types for this sort of thing: https://github.com/rust-lang/rust/issues/135996 https://github.com/rust-lang/rust/issues/135996