It is possible to write constructions like this:
enum Number {
One = 1,
Two = 2,
Three = 3,
Four = 4,
}
but for what purpose? I can't find any method to get the value of an enum variant.
It is possible to write constructions like this:
enum Number {
One = 1,
Two = 2,
Three = 3,
Four = 4,
}
but for what purpose? I can't find any method to get the value of an enum variant.
You get the value by casting the enum variant to an integral type:
enum Thing {
A = 1,
B = 2,
}
fn main() {
println!("{}", Thing::A as u8);
println!("{}", Thing::B as u8);
}