rustEnum example in Rust
Enums in Rust are a way to define a type by enumerating its possible variants. They are useful for representing a fixed set of values, such as the four suits in a deck of cards. An example of an enum in Rust is the following:
enum Suit {
Spades,
Hearts,
Diamonds,
Clubs,
}
Output example
This code does not produce any output.
Explanation
The enum
keyword is used to declare an enum type. The type is named Suit
and it has four variants: Spades
, Hearts
, Diamonds
, and Clubs
. Each variant is separated by a comma.
Relevant links
Enums in the Rust Book Enums in the Rust Reference Enums in the Rust by Example
Related
More of Rust
- How to match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to split a string with Rust regex?
- How to iterate over a Rust slice with an index?
- How to use negation in Rust regex?
- How to use regex captures in Rust?
- Regex example to match multiline string in Rust?
- How to get a capture group using Rust regex?
- How to use modifiers in a Rust regex?
- How to create a HashMap of structs in Rust?
See more codes...