Open
Description
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.,
#[derive(Variant)]
#[variant(fixed, rename_all = "camelCase")] // optional; default is extensible per <https://aka.ms/azapi/guidelines>
pub enum DaysOfWeek {
Monday,
Tuesday,
// ...
}
#[derive(Variant)]
#[variant(rename_all = "camelCase")]
pub enum Metasyntactic {
Foo,
Bar,
#[variant(other)] // UnknownValue(String) is used by default, actually
UnknownValue(String),
}
The Variant
derive macro would:
- Derive
Clone
,Debug
,PartialEq
, andEq
- Implement
serde::Serialize
andserde::Deserialize
- Implement
FromStr
. Extensible enums will defineFromStr::Err
asstd::convert::Infallible
but fixed enums usingazure_core::ErrorKind::DataConversion
. This will be used inserde::Deserialize
. - Implement
Display
. This will be used inserde::Serialize
.
See #1690
Question(s) on top of mind:
- Should we try to duplicate necessary
serde
attributes likerename_all
? Off hand, that may be all we need. - Should we define a
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?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Not Started