Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum tag support #6

Open
sucaba opened this issue Sep 12, 2020 · 0 comments
Open

Enum tag support #6

sucaba opened this issue Sep 12, 2020 · 0 comments

Comments

@sucaba
Copy link

sucaba commented Sep 12, 2020

Hi,
I'm trying to implement Debug or Format for enums (yes, I know about the derive) and
don't want to hardcode enum tag names as strings.
Potentially, enum tags can change names in future and I want to be sure that print-ed values will follow names.
Was thinking about using nameof for this. For instance:

    enum Color {
        Red(i32),
        Green(i32),
        Blue(i32),
    }
   
    name_of!(enum Color::Green(42));
   // or
   tag_of!(Color::Green(42));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant