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
- How to create enum from string in Rust
- How to use enum as hashmap key in Rust
- How to create enum from number in Rust
- How to use fmt for enum in Rust
- How to declare enum in Rust
- How to compare enum in Rust
- How to serialize enum in Rust
- How to loop through enum in Rust
- How to cast enum in Rust
- Get certain enum value in Rust
More of Rust
- Hashshet example in Rust
- How to convert Rust bytes to hex?
- How to convert a Rust HashMap to a JSON string?
- How to convert a Rust HashMap to JSON?
- How to get the last element of a Rust slice?
- How to use non-capturing groups in Rust regex?
- How to use groups in a Rust regex?
- How to match the end of a line in a Rust regex?
- How to escape dots with regex in Rust?
- How to use regex to match a group in Rust?
See more codes...