Enum Ordinalize

Build Status Build status

Make an Enum Ordinalized

ordinalize_enum macro can implement a ordinal method and a from_ordinal associated function for an existing enum.

```rust

[macrouse] extern crate enumordinalize;

[derive(Debug, PartialEq)]

enum MyEnum { Zero, One, Two, }

ordinalize_enum!(MyEnum, u8, Zero, One, Two );

asserteq!(2, MyEnum::Two.ordinal()); asserteq!(Some(MyEnum::One), MyEnum::from_ordinal(1)); ```

Create an Ordinalized Enum

create_ordinalized_enum macro can create an enum and implement a ordinal method and a from_ordinal associated function for it. The new enum also implements Debug, PartialEq, and Clone traits.

```rust

[macrouse] extern crate enumordinalize;

createordinalizedenum!(MyEnum, u8, Zero, One, Two );

asserteq!(2, MyEnum::Two.ordinal()); asserteq!(Some(MyEnum::One), MyEnum::from_ordinal(1));

createordinalizedenum!(pub MyPublicEnum, u8, A, B, C );

asserteq!(2, MyPublicEnum::C.ordinal()); asserteq!(Some(MyPublicEnum::B), MyPublicEnum::from_ordinal(1));

createordinalizedenum!(MySpecialEnum, u8, Two = 2, Four = 4, Eight = 8 );

asserteq!(2, MySpecialEnum::Two.ordinal()); asserteq!(Some(MySpecialEnum::Four), MySpecialEnum::from_ordinal(4)); ```

Crates.io

https://crates.io/crates/enum-ordinalize

Documentation

https://docs.rs/enum-ordinalize

License

MIT