If I want to know the discriminant of an enum variant, all I need to do is my_variant as usize
(or whatever {integer}
type). What if I have the discriminant, and I want to get the corresponding variant ?
I obviously tried the reverse my_int as MyEnum
, but it (unsurprisingly) didn't work.
enum Enu {
X,
Y,
}
fn main() {
let discr_x = Enu::X as usize;
let x = magic(discr_x);
}
x
should be Enu::X