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.

Struct getters #3

Description

@alekratz

For example,

#[derive(EnumGetters)]
enum MyEnum {
    Foo { bar: i32, baz: String },
}

currently does not create an implementation.

My solution would be to implement a getter for each item.

fn main() {
    let mine = MyEnum::Foo { bar: 42, baz: "In the clearing stands a boxer".to_string() };
    // Items are named after the enum, and then their name in snake_case
    println!("bar is: {}", mine.foo_bar());
    println!("baz is: {}", mine.foo_baz());
}

My only concern is that this can get wordy when using snake_case.

If you think you have something more ergonomic (or overall better!) please suggest it here.

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