enum-utils icon indicating copy to clipboard operation
enum-utils copied to clipboard

Override visibility and/or name for `IterVariants`

Open abonander opened this issue 4 years ago • 0 comments

It appears that the IterVariants derive will only produce a private fn iter() which makes it only useful in the module where the enum is defined. I'd like to see a way to override this:

pub mod foo {
    #[derive(enum_utils::IterVariants)]
    // well-behaved attributes are namespaced
    // also so you only have to declare the `enum_utils` attribute in `#[proc_macro_derive]`
    #[enum_utils(iter(visibility = "pub"))]
    pub enum Foo {
        Bar,
        Baz
    }
}

fn main() {
    let variants = foo::Foo::iter();
}

Additionally, it might be nice to override the generated method name:

#[derive(enum_utils::IterVariants)]
#[enum_utils(iter(name = "variants"))]
enum Foo {
    Bar,
    Baz
}

fn main() {
    let variants = Foo::variants();
}

abonander avatar Jan 20 '21 03:01 abonander