A simple macro that implements prev()
and next()
methods to an enum in Rust
Sometimes you define an enum like this
rust
enum Direction {
Up,
Left,
Down,
Right,
}
and you want to rotate them in some logic,
```rust let up = Direction::Up; let left = Direction::Left; let down = Direction::Down; let right = Direction::Right;
assert!(up.next() == left); assert!(left.next() == down); assert!(down.next() == right); assert!(right.next() == up);
assert!(up.prev() == right); assert!(left.prev() == up); assert!(down.prev() == left); assert!(right.prev() == down); ```
You can of course implement these methods manually, but it's repetitive and error prone.
Don't you think it should be automated?
This crate provides a RotateEnum
derive macro to just do this.
```rust use rotate_enum::RotateEnum;
enum Direction { Up, Left, Down, Right, } ```