Skip to content
This repository was archived by the owner on Sep 15, 2026. It is now read-only.
This repository was archived by the owner on Sep 15, 2026. It is now read-only.

Exclusion attributes #10

Description

@alekratz

Sometimes it is not desirable to generate a method for a variant of an enum. Presently, there is no way to skip over some specific element. I think we should add a per-element attribute that tells a given derive to skip that element. For example:

struct MyType;

#[derive(EnumToGetters, EnumAsGetters)]
enum MyEnum {
    #[enum_as_getters(skip)]
    Foo(i32), // EnumAsGetters will return a reference to this; we we override `as_foo()` below
    #[enum_to_getters(skip)]
    Bar(MyType), // MyType is not `Clone`, so EnumToGetters would fail to compile on this
}

impl MyEnum {
    pub fn as_foo(&self) -> i32 {
        if let &MyEnum::Foo(i) = self {
            *i
        }
        else { panic!( ... ) }
    }
}

This is also similar to how Serde works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions