Provides the procedural macro FromToRepr
which can be applied to a enum with an explicit representation (e.g #[repr(u8)]
) and derives TryFrom
from the representation type to the enum and From
from the enum to the representation type.
As an example,
```rust
enum ColorChannel { RED = 0, GREEN = 1, BLUE = 2, } ```
becomes
```rust
enum ColorChannel {
RED = 0,
GREEN = 1,
BLUE = 2,
}
impl ::std::convert::TryFrom
Additionally, when the feature from_to_other
is enabled, an attribute macro named from_to_other
is enabled, which generates conversions to and from a base type, representing unknown values using an Other
enum variant. For example:
```rust use fromtorepr::fromtoother;
enum ColorCommand {
SetRed = 0,
SetGreen = 1,
SetBlue = 2,
Other(u8),
}
is equivalent to
rust
enum ColorCommand {
SetRed,
SetGreen,
SetBlue,
Other(u8),
}
impl ::core::convert::From