-
Notifications
You must be signed in to change notification settings - Fork 248
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
Create derive macro for variants (enums) #1846
Comments
In the meantime, I created a |
I like
If we're hand-implementing the Since we're not actually deriving a trait, it might also be reasonable to use a general attribute macro, rather than a |
The goal is to create a derive macro, though, and specifically so we could have helper attributes; though, if we could easily enough still handle helper attributes to customize the enum or individual variants I'd still be open to that. Some earlier prototypes I couldn't make work but - especially back then - hadn't gotten my hands quite so dirty into And, yes, I'd want to support individual |
That's correct. |
Ah yeah, if we need helper attributes, I agree a derive macro is likely the best option. With a plain attribute macro we could still support helper attributes, but we're entirely on our own to extract them from the |
Because Azure services define a lot of enums and, despite generating most of our clients, hand-authored enums could benefit from consistency with our guidelines, we should create a derive macro for enums called, tentatively,
Variant
e.g.,The
Variant
derive macro would:Clone
,Debug
,PartialEq
, andEq
serde::Serialize
andserde::Deserialize
FromStr
. Extensible enums will defineFromStr::Err
asstd::convert::Infallible
but fixed enums usingazure_core::ErrorKind::DataConversion
. This will be used inserde::Deserialize
.Display
. This will be used inserde::Serialize
.See #1690
Question(s) on top of mind:
serde
attributes likerename_all
? Off hand, that may be all we need.Variant
trait for which we can add blanket implementations that are easier to update than a derive macro? Is that even practical? Seems we'd need aVariant
trait to return tuples of tokens to values which might make the whole thing inefficient.#[variant(other)]
is meant to be equivalent to#[serde(untagged)]
but I feel is more intuitive; or, should we make these the same for familiarity?The text was updated successfully, but these errors were encountered: