#enums #index #repr #macro #getting #enum-index

enum_index_repr

EnumIndexRepr provides a small macro which allows getting the index on an enum

4 releases

0.2.1 Nov 25, 2022
0.2.0 Nov 25, 2022
0.1.1 Nov 25, 2022
0.1.0 Nov 25, 2022

#1963 in Rust patterns

MIT license

2KB

EnumIndex

EnumIndex provides a small macro which implements EnumIndexGet, permitting the following:

use enum_index_repr::{EnumIndex, EnumIndexGet};

#[repr(u16)]
#[derive(EnumIndex)]
enum Tag {
    Hello,
    World,
    How,
    Are,
    You,
}

fn main() {
    assert_eq!(Tag::How.index(), 2);
}

Dependencies

~1.5MB
~33K SLoC