Skip to main content


Hi !

How can I convert an "i32" variable to an enum value in #rust ? :rust:

The "cast" will be in the expression of a match.

I have seen some things about deriving "TryFrom" or "FromPrimitive" traits, but I'm not sure that's up to date.

I believe it's possible, but... how ?

Please, if you know how it works, tell me. x)
#rust
At the moment I'd go with TryFrom, looks like the most accurate way to me. FromPrimitive is still experimental, and at least at first sight it doesn't feel "right" to me for that use case.