Hi folks! Why does the first line print 8? Also, the scond line prints 16, is that because Option contains two variants Some and None which is equivalent to containing two usize (discriminant)?
&usize can't be "null" (0), so Option can use that value to represent the None case. In the second case it needs to store the Some/None distinction in another memory location.
You can use your favorite search engine to search for "rust niche optimization" to read more about it.
one can point out that 8 bytes isn't enough to distinguish all the possible values, and that the usize must be stored in an aligned location (you can get a reference to it without removing it from the Option), so the size must be a multiple of 8 which is greater than 8.
But exactly how the discriminant is stored[1] is an implementation detail.
is it a usize, is it a byte, which byte, what values... ↩︎
Not really editions because they need to interoperate (while the compiler could technically save the edition of the type, it doesn't currently). But versions of the compiler, sure.