Add the strum crate to your Cargo.toml and use the #[derive] macro with specific traits like Display or EnumIter on your enum to generate helper methods.
[dependencies]
strum = "0.26"
strum_macros = "0.26"
use strum_macros::{Display, EnumIter};
#[derive(Display, EnumIter)]
enum Color {
Red,
Blue,
}
fn main() {
println!("{:?}", Color::Red); // Prints "Red"
for color in Color::iter() {
println!("{:?}", color);
}
}