Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Proposal: Exclude macro for EnumIter macro #290

Open 1uf3 opened 1 year ago

1uf3 commented 1 year ago

I would like a macro that does not put only certain elements in the EnumIter that creates an iterator for all Enum elements.

Example.

use strum::IntoEnumIterator;
use strum_macros::EnumIter;

#[derive(EnumIter, Debug, PartialEq)]
enum Color {
    Red,
    Green { range: usize },
    Blue(usize),
    #[exclude]
    Yellow,
}

let mut ci = Color::iter();
assert_eq!(Some(Color::Red), ci.next());
assert_eq!(Some(Color::Green {range: 0}), ci.next());
assert_eq!(Some(Color::Blue(0)), ci.next());
assert_eq!(None, ci.next());