Don't forget to add the niche
Rust is my favorite programming language. One of the many things I love about Rust is its layout optimizations that allow you to use high-level data types while still getting the same, or even better size and cache optimality than you would with C/C++. Possibly Rust's most impressive layout optimization is the famous niche optimization for enums, which is also, unfortunately, not the best advertised or the most obvious to exploit. When I'm writing Rust code, I use enums, especially Option and Result , all the time , so I've gotten somewhat keen to the mechanics of the optimization. In my opinion, it could stand to be easier to trigger; if you don't know the rules of niche optimization, you're almost certainly leaving cheap or free performance on the table. In some cases, the unused space is already there in your enum, going unused, but the compiler will not perform niche optimization unless you explicitly add a niche to your struct. Playground link with all ex...