[][src]Crate ordinalizer

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.


use ordinalizer::Ordinal;
enum Animal {
    Cat {
        age: i32,

assert_eq!(Animal::Dog.ordinal(), 0);
assert_eq!((Animal::Cat { age: 10 }).ordinal(), 1);

Derive Macros


Generates a fn ordinal(&self) -> usize for an enum.