serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
9.06k stars 767 forks source link

Sometimes (de)serialise enum with tag, sometimes untagged. #2752

Open emilyyyylime opened 4 months ago

emilyyyylime commented 4 months ago

My use case requires being able to serialise an enum as untagged, but usually when deserialising it, I do want the tag present (as adjacently tagged, specifically). As my enum is really long, it would be a big hassle to have to specify it twice over.

It would be really helpful to me to be able to write #[serde(untagged)] (and perhaps the other forms too) on struct fields that are themselves enums or on newtype structs that contain enums.