Skip to content

Override visibility and/or name for IterVariantsΒ #4

@abonander

Description

@abonander

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions