concept enum in category rust

appears as: enum, n enum, An enum, enums, Enums, enum
Rust in Action

This is an excerpt from Manning's book Rust in Action.

So, what is a Result? Result is an enum defined in Rust’s standard library. It has the same status as any other type, but is tied together with the rest of the language through strong community conventions. Wait.. what is an enum? I’m glad you asked. That’s the topic of our next section.

3.5. Defining and making use of enum

An enum—enumeration in full—is a type that can represent multiple known variants. Classically, an enum would be used to represent several pre-defined known options, such as the suits of playing cards or planets in the solar system.

Listing 3. 14. Defining an enum that represents the suits of a French deck of playing cards
enum Suit {
  Clubs,
  Spades,
  Diamonds,
  Hearts,
}

If you haven’t programmed in a language that makes use of enums, understanding their value takes some effort. As you program with them for a while, you’re likely to experience a minor epiphany. Consider creating some code that is parsing event logs. Each event has a name, perhaps “UPDATE” or “DELETE”. Rather than storing those values as strings in your application, which can lead to subtle bugs later on when string comparisons become unwieldy, enums allow you to give the compiler some knowledge of the error codes. Later on, you’ll be given warnings such as “Hi there, I see that you have considered the UPDATE case, but it looks like you’ve forgotten the DELETE case. You should fix that.”