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

fix EnumIter for enums with const generic #293

Closed PingPongun closed 10 months ago

PingPongun commented 1 year ago

Currently, EnumIter for struct with constant generic results in error E0747 (constant provided when a type was expected). That's because generated iter struct looks sth like:

struct LanguageIter<LAUNCHER> {
        idx: usize,
        back_idx: usize,
        marker: ::core::marker::PhantomData<()>,
    }

for enum:

#[derive( EnumIter)]
enum Language<const LAUNCHER: bool> {...}

Which is ok for ordinary(type) generics, but for const generics iter struct definition has to look like:

struct LanguageIter<const LAUNCHER: bool> {...}

this PR makes EnumIter work with const generics, by using $impl_generics instead of $ty_generics for struct definition. Also added const generic to enum in tests.

Peternator7 commented 10 months ago

Looks good. Thanks for the fix :)