Bytenum

Bytenum is a rust derive macro that creates a try_from implementation for an enum with unit variants.

Usage

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;

[derive(Bytenum, Debug, PartialEq)]

enum Color { Red, Green, Blue, }

[test]

fn convertvariants() -> Result<(), Box> { [Color::Red, Color::Green, Color::Blue] .intoiter() .enumerate() .tryforeach(|(value, color)| { asserteq!(color, Color::tryfrom(value as u8)?); Ok(()) }) } ```