num-derive icon indicating copy to clipboard operation
num-derive copied to clipboard

FromPrimitive with values not covered by existing enum

Open soumya92 opened this issue 5 years ago • 0 comments

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,
...

soumya92 avatar Aug 30 '19 04:08 soumya92