Add create_extensible_enum macro#1852
Conversation
8972440 to
ba157ec
Compare
|
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). |
LarryOsterman
left a comment
There was a problem hiding this comment.
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))), *);
); |
No description provided.