RotateEnum

Derive Macro RotateEnum 

Source
#[derive(RotateEnum)]
Expand description

This derive macro will implement next() and prev() methods that rotates the variant to the annotated enum.

For code examples, see module-level docs.

§Requirements

  • It must be applied to an enum. Structs are not supported or won’t make sense.
  • Enums with any associated data are not supported.

§Generated methods

For example, this macro will implement functions like below for enum Direction.

impl Direction {
    fn next(self) -> Self {
        match self {
            Self::Up => Self::Left,
            Self::Left => Self::Down,
            Self::Down => Self::Right,
            Self::Right => Self::Up,
        }
    }

    fn prev(self) -> Self {
        match self {
            Self::Up => Self::Right,
            Self::Left => Self::Up,
            Self::Down => Self::Left,
            Self::Right => Self::Down,
        }
    }
}