A surprising enum size optimization in the Rust compiler ยท post by James Fennell
April 7, 2025
Enums are one of the most popular features in Rust.
An enum is type whose value is one of a specified set of variants.
/// Foo is either a 32-bit integer or character.
enum Foo {
Int(u32),
Char(char),
}
Values of type Foo are either
integers (e.g. the variant Foo::Int(3) with a payload of 3)
or characters (e.g. the variant Foo::Char('A') with a payload of 'A').
If you think of structs as being the and combination of their fields,
enums are the or combination of their variants.
This...
Read more at jpfennell.com