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

EnumIter does not work for enums named 'Option' #299

Closed horacimacias closed 1 year ago

horacimacias commented 1 year ago

I'm using some code that has generated structs and enums, and some of the enumerations are called Option. They are on their own module/crate but there seems to be a conflict with the std::option::Option.

The following does work (note Options, not Option as the name of the enum)

#[derive(strum_macros::EnumIter, Debug)]
pub enum Options {
    Open,
    Closed,
}

use strum::IntoEnumIterator;
fn main() {
    for variant in crate::Options::iter() {
        println!("The door is {:?}", variant);
    }
}

the following does not work (the name of the enum is now Option)

#[derive(strum_macros::EnumIter, Debug)]
pub enum Option {
    Open,
    Closed,
}

use strum::IntoEnumIterator;
fn main() {
    for variant in crate::Option::iter() {
        println!("The door is {:?}", variant);
    }
}