Open
Description
This is a problem that has come up a lot. The most recent discussion I could find about it is the internals thread here, but that thread has been locked and I figured this should probably have an "official" issue somewhere.
There's currently no (good) way to convert from an enum integer discriminant value to the enum itself. Enums should support deriving TryFrom
for this purpose. eg.
#[repr(u32)]
#[derive(TryFrom)]
enum MyCoolEnum {
Foo = 1,
Bar = 2,
}
let x: u32 = ... ;
let my_cool_enum = MyCoolEnum::try_from(x).expect("invalid discriminant!");