Bytenum is a rust derive macro that creates a try_from
Add this to your Cargo.toml
:
toml
bytenum = "0.1.0"
And then add then add a derive Bytenum
attribute on an enum
that has less than 256
variants (the amount that can be represented by a u8
).
Now you can use can convert an enum variant to a u8
with try_from
.
rust
Color::try_from(value as u8)?
Example:
```rust use bytenum::Bytenum;
enum Color { Red, Green, Blue, }
fn convertvariants() -> Result<(), Box