Let's say I have an enum with two variants including discriminant values:
enum E {
A = 1,
B = 2,
}
I can easily convert E
into, say, an i32
by doing:
fn f() {
let e = E::A;
let i = e as i32;
}
When trying the reverse I would expect the following to work:
fn g(i: i32) {
let e: E = i.try_into().unwrap(); // E0277: the trait bound `E: std::convert::From<i32>` is not satisfied
}
What is the shortest / most idiomatic way to do this without writing a separate match
implementation myself?