serde
serde copied to clipboard
Question: Why can't `#[serde(default)]` be applied to enums?
It seems like it might be viable to have #[serde(default)] for an enum that implements Default. I could imagine this being challenging for an externally tagged enum since the type (object or string?) isn't known a priori, but at least would this be viable for an internally- or adjacently-tagged enum since it they're equivalent to structs with constraints?
struct AdjacentEnum {
tag: VariantPartOfEnum,
contents: ContentsPartOfEnumIfItWereUntagged,
}
struct InternalEnum {
tag: VariantPartOfEnum,
#[serde(flatten)]
contents: ContentsPartOfEnumIfItWereUntagged,
}
If any of this seems reasonable I would be happy to put together a PR.