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

Add create_extensible_enum macro #1852

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

heaths
Copy link
Member

@heaths heaths commented Oct 14, 2024

No description provided.

@heaths heaths changed the title extensible enum Add create_extensible_enum macro Oct 14, 2024
@heaths heaths changed the base branch from main to feature/track2 October 14, 2024 21:43
@heaths
Copy link
Member Author

heaths commented Oct 14, 2024

This uses a little "trick" of characters really only usable in macros to effectively make a match arm "internal". We can use this for shared code for DRY. I probably could've gone a little further with some creative match arms, but I think that'd diminish readability and these macros are hopefully temporary anyway (see #1846).

Copy link
Member

@LarryOsterman LarryOsterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm annoyed by the redundancy associated with having to say Black, "Black" and the potential for subtle bugs, but absent adding the ability for rust to introduce a tokenizing operator, I don't see a way of avoiding it.

@heaths heaths merged commit 64a1b19 into Azure:feature/track2 Oct 14, 2024
28 checks passed
@heaths
Copy link
Member Author

heaths commented Oct 14, 2024

I'm annoyed by the redundancy associated with having to say Black, "Black" and the potential for subtle bugs, but absent adding the ability for rust to introduce a tokenizing operator, I don't see a way of avoiding it.

It actually wouldn't be that hard and I had considered it, but it's of dubious value because 1) these are temporary, and 2) they wouldn't likely be used in emitters because it'd be harder - and rather pointless - to vary the emitted code. I suppose, also, 3) it's not that much more to type in what few hand-coded cases there should be but, again, see point 1.

Oh, and 4) enums in the REST API are supposed to be camelCase anyway, so it should be rare that names and values are both PascalCase.

All we'd have to do is add a match arm like so:

    ($(#[$type_meta:meta])* $name:ident, $($(#[$value_meta:meta])* $variant:ident), *) => (
        create_enum!($(#[$type_meta])* $name, $($(#[$value_meta])* ($variant, stringify!($variant))), *);
    );

@heaths heaths deleted the extensible-enum branch October 14, 2024 22:59
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

Successfully merging this pull request may close these issues.

4 participants