1 unstable release
0.1.0 | May 6, 2020 |
---|
#21 in #ordinal
100 downloads per month
Used in 3 crates
7KB
73 lines
A simple derive macro to generate an ordinal()
method for enums.
Unlike num_derive::ToPrimitive
, this derive macro
allows non-C-like enums. The ordinal
function reflects
the variant of the enum and does not account
for fields.
Example
use ordinalizer::Ordinal;
#[derive(Ordinal)]
enum Animal {
Dog,
Cat {
age: i32,
}
}
assert_eq!(Animal::Dog.ordinal(), 0);
assert_eq!((Animal::Cat { age: 10 }).ordinal(), 1);
Dependencies
~1.5MB
~37K SLoC