Comment on Rust's Two Kinds of 'Assert' Make for Better CodeparentComments−dwattttt1yI don't think the mechanics of being able to convey a niche are stable/developer-accessible, but NonZero is a type provided by the standard library: https://doc.rust-lang.org/std/num/struct.NonZero.htmlAn example of the niche optimisations is in that link; if a 32bit number is NonZero, you can put that in an Option, and your Option<NonZero<u32>> will be the same size as a normal u32.−phamilton1yAn interesting project for niche types: https://github.com/rick-de-water/nonanyIt's not perfect but does allow some flexibility.
Comments
I don't think the mechanics of being able to convey a niche are stable/developer-accessible, but NonZero is a type provided by the standard library: https://doc.rust-lang.org/std/num/struct.NonZero.html
An example of the niche optimisations is in that link; if a 32bit number is NonZero, you can put that in an Option, and your Option<NonZero<u32>> will be the same size as a normal u32.
An interesting project for niche types: https://github.com/rick-de-water/nonany
It's not perfect but does allow some flexibility.