How to get value from within enum in a nice way, again

I have the same problem as in "How to get value from within enum in a nice way".

I have to write, where enumvalue is an instance of an enum EnumType,

let value = match enumvalue {
    EnumType::u32(val) => val,
    _ => return Err(anyhow!("Expected u32")

The suggested workaround is lots of custom macros. Is there anything available like this:

let value = u32::try_from(enumvalue)?;

One would expect something like that to be available. It's a common enough case.

There aren't any built-in derives or methods for unwrapping enum variants. You can implement TryInto (or add methods to your type) manually if you don't want to use a macro to do it.

There's also the derive_more crate.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.