macro_rules! enum_with_unknown {
(
$( #[$enum_attr:meta] )*
pub enum $name:ident($ty:ty) {
$(
$( #[$variant_attr:meta] )*
$variant:ident = $value:expr
),+ $(,)?
}
) => { ... };
}Expand description
Derive To/From with an added “Unknown” variant catch-all for converting from numerical values that do not match a valid variant in order to avoid either panicking or cumbersome error handling.
Yoinked shamelessly (with some modification) from smoltcp.