rustHow to use fmt for enum in Rust
To use fmt for enum in Rust, you can use the following template:
#[derive(Debug)]
enum EnumName {
Variant1,
Variant2,
Variant3,
}
fn main() {
let enum_instance = EnumName::Variant1;
println!("{:?}", enum_instance);
}
The output of this code will be:
Variant1
The #[derive(Debug)] attribute allows us to use the println! macro to print out the enum instance. The :? format specifier is used to print out the enum instance in a debug format.
Helpful links
Related
More of Rust
- How to use regex to match a double quote in Rust?
- How to insert an element into a Rust HashMap if it does not already exist?
- How to use Unicode in a regex in Rust?
- How to match digits with regex in Rust?
- How to use captures_iter with regex in Rust?
- How to compare two Rust HashMaps?
- Yield example in Rust
- How to create a generator iterator in Rust?
- How to convert a Rust slice to a fixed array?
- How to use regex to match a group in Rust?
See more codes...