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 replace strings using Rust regex?
- How to parse JSON string in Rust?
- How to convert the keys of a Rust HashMap to a vector?
- How to escape dots with regex in Rust?
- How to add matrices in Rust?
- How do I copy a variable in Rust?
- How to parse a file with Rust regex?
- How to declare a constant HashSet in Rust?
- How to get all values from a Rust HashMap?
- How to convert a Rust HashMap to a BTreeMap?
See more codes...