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 lookbehind in Rust?
- How to use binary regex in Rust?
- How to match a URL with a regex in Rust?
- Regex example to match multiline string in Rust?
- How to ignore case in Rust regex?
- How to use regex captures in Rust?
- How to perform matrix operations in Rust?
- How to replace strings using Rust regex?
- How to make regex case insensitive in Rust?
- How to use backslash in regex in Rust?
See more codes...