num-derive
num-derive copied to clipboard
FromPrimitive with values not covered by existing enum
If I have
enum Foo {
FooA = 3,
FooB = 7,
OtherFoo(u8),
}
it would be nice to have some way to specify that:
Foo::from_u8(3) == Some(FooA),
Foo::from_u16(7) == Some(FooB),
Foo::from_u8(4) == Some(FooOther(4)),
Foo::from_i32(5) == Some(FooOther(5)),
Foo::from_i32(1024) == None,
...