Re:Why Rust helps even if you have to use a lot of `unsafe`
by CodesInChaos on Wednesday August 02, 2023 @12:21PM
(#36973026)
The overhead isn't always 8 bytes. When the type uses the naive representation, the overhead will generally match the alignment. For example an Option<u8> costs 2 bytes, 1 of which is for the tag.
And if the type has some illegal values, these can sometimes be used to discriminate the type. For example Option<&T> matches the size of &T, since it uses the illegal null value to represent None.
And if the type has some illegal values, these can sometimes be used to discriminate the type. For example Option<&T> matches the size of &T, since it uses the illegal null value to represent None.