I would like to write a function that toggles / switches the provided value to the following in the listing and wraps at the end:
enum Direction { NORTH, SOUTH, EAST, WEST }
For example, NORTH => SOUTH , SOUTH => EAST , EAST => WEST , WEST => NORTH .
Is there an easier way than manually creating a static array, as described in Rust, is there a way to iterate over enum values?
use Direction::*; static DIRECTIONS: [Direction; 4] = [NORTH, SOUTH, EAST, WEST];
Are enumerations not "enumerated"? I vaguely remember how I saw an example in Rust before, but I can not find it. Since Rust enums are more like unions / options, I assume this complicates the situation.
source share