Add a utility function to convert a usize into an Enum
Currently, you have to use the expression <T as Enum<()>>::from_usize(value)
, which is basically a magic incantation you have to remember. It would be nice if there were a generic function that can do this on the toplevel:
fn try_from_usize<T: Enum>(n: usize) -> Option<T> {
if n < <T as Enum<()>>::POSSIBLE_VALUES {
Some(<T as Enum<()>>::from_usize(n))
} else {
None
}
}