Enum Ordinalize
This crates provides create_ordinalized_enum
macro to let enums can not only get its variants' ordinal but also be constructed from an ordinal.
Create an Ordinalized Enum
create_ordinalized_enum
macro can create an enum and implement a ordinal
method, as well as from_ordinal
and from_ordinal_unsafe
associated functions for it.
The new enum also implements Debug
, PartialEq
, and Clone
traits.
extern crate enum_ordinalize;
create_ordinalized_enum!;
assert_eq!;
assert_eq!;
create_ordinalized_enum!;
assert_eq!;
assert_eq!;
create_ordinalized_enum!;
assert_eq!;
assert_eq!;
About an Ordinalized Enum
An ordinalized enum is always sized isize in order to directly transmute into an isize value, or conversely. There is a variant named __DotNotUse whose ordinal is always the maximum of an isize value for every ordinalized enum.
If you are 100% sure that the isize value can transmute into a variant of your ordinalized enum. You can use from_ordinal_unsafe
associated function and unsafe keyword to speed up.
extern crate enum_ordinalize;
create_ordinalized_enum!;
assert_eq!;
Crates.io
https://crates.io/crates/enum-ordinalize
Documentation
https://docs.rs/enum-ordinalize