|
|
|
|
|
by zdimension
246 days ago
|
|
For anyone wondering, NonNull (along with other "constrained" types like NonZero integers) uses internal compiler attributes (https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#72): #[rustc_layout_scalar_valid_range_start(1)]
This gives rustc enough information to perform niche optimizations such as collapsing Option<NonNull<T>>.You can technically use those for your own types, but it requires nightly, obviously. |
|
If you have a USHoliday enum, with values like Juneteenth the fact is there's not that many US national holidays, so both USHoliday and Option<USHoliday> will be the same size, one byte with no extra work.