Fun fact: size of Option<String>

157 points SssstevenH

Did you know that the size of Option<String> is 3 words while the size of String is also 3 words? I didn't know it until I was checking Rust Analyzer's hint for one of my enums today.

This is surprising because enums such as Option<T> carry extra information in a tag and pad the whole struct to align with word size (with some exceptions). So, the compiler probably optimized away the extra size needed somewhere.

My guess is that the None corresponds to the case where null is the Unique<u8> in RawVec<u8> in Vec<u8> in String.