October 2019
Intermediate to advanced
444 pages
10h 37m
English
Enums in Rust encapsulate choices—just as in any language. However, they behave similarly to regular structures in a lot of ways:
These aspects make them really great candidates for choices of all kinds, be it configuration values, flags, constants, or wrapping errors, as we did in Step 2. Typical enums in other languages map a name to a numerical value of your choice, but Rust goes one step further. Instead of just numerical values, Rust's enum can have any value and even named properties. Take a look at the definition in Step 2:
pub enum ApplicationError { Code { full: usize, short: u16 }, Message(String), IOWrapper(io::Error), ...Read now
Unlock full access