Enums in Rust are optimized for memory usage, resulting in smaller representations for certain types. The article explains how the Rust compiler employs techniques like niche optimization and memory representation to efficiently manage enum sizes, particularly in nested enums. It highlights surprising findings, such as the compiler's ability to use tags and niches effectively to minimize memory overhead.
Error handling in Rust commonly involves defining large error enums that may include irrelevant variants for a function's context. The author argues for a more granular approach using structs to represent individual errors and introduces a crate that simplifies error handling through macros, allowing concise definitions of error sets. Despite some verbosity, the new paradigm alleviates the burden of managing extensive error enums while retaining type safety.