#[derive(DeriveIndex)]
Expand description

impls a trait for a struct that automatically converts each enum variant into an index and converts an index into an Option enum variant. As an example, let’s take a simple enum

pub enum Example {
    One,
    Two,
    Three   
}

This derive macro will automatically implement a trait called custom_enum_traits::EnumIndex that looks like this:

impl EnumIndex for Example {
    fn from_index(idx: usize) -> Option<Example> {
        match idx {
            0 => Some(Example::One),
            1 => Some(Example::Two),
            2 => Some(Example::Three),
            _ => None
        }
    }   

    fn to_index(&self) -> usize {
        match self {
            Example::One => 0,
            Example::Two => 1,
            Example::Three => 2
        }
    }
}