Skip to content

Add EnumVariantNames derive to relevant enums #32

@VRichardJP

Description

@VRichardJP

I just stumbled upon EnumVariantNames which can be used to create a static list of an enum variant. I think it would be nice to use it for the constant enums defined in src/consts/*.rs (and maybe some other places too)

For example, let's say I am writing a cli interface and I want the user to input a server (or champion, or tier, etc), currently I have to do something ugly like:

let server_strings = PlatformRoute::iter().map(|server| &server.to_string() as &str).collect::<Vec<&str>>();
let matches = App::new("my awesome app")
    .arg(Arg::new("server")
        .about("Selected server")
        .short("s")
        .long("server")
        .possible_values(&server_strings)
    )

While with EnumVariantNames I could simply write

let matches = App::new("my awesome app")
    .arg(Arg::new("server")
        .about("Selected server")
        .short("s")
        .long("server")
        .possible_values(PlatformRoute::VARIANTS)
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions