You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
If you create an enum that contains a newtype variant, wrap the enum in a struct, wrap the said struct in another struct and use #[serde(flatten)] on it, the struct can no longer successfully deserialize (while serialization is unaffected).
Deserialization fails with message: untagged and internally tagged enums do not support enum input.
That's not a very helpful description so here's a MRE:
use serde::{Deserialize,Serialize};fnmain(){// this workslet gender = Gender::Other("F22".into());assert_eq!(&gender,&serde_yaml::from_str(&dbg!(serde_yaml::to_string(&gender).unwrap())).unwrap());// this still workslet info = Info{ gender };assert_eq!(&info,&serde_yaml::from_str(&dbg!(serde_yaml::to_string(&info).unwrap())).unwrap());// this errorslet user = User{ info };assert_eq!(&user,&serde_yaml::from_str(&dbg!(serde_yaml::to_string(&user).unwrap())).unwrap());}#[derive(Clone,Debug,Eq,PartialEq,Deserialize,Serialize)]enumGender{Female,Male,Other(String),}#[derive(Clone,Debug,Eq,PartialEq,Deserialize,Serialize)]structInfo{gender:Gender,}#[derive(Clone,Debug,Eq,PartialEq,Deserialize,Serialize)]structUser{#[serde(flatten)]info:Info,}
Misc
I tried the exact same example using serde_json, no errors. So I think this is a serde_yaml issue rather than a serde issue.
A quick search did find this issue though, not sure if it's related: ron-rs/ron#217.
Versions
OS: Linux 6.0.8 x86_64
rust: 1.65.0 (stable-x86_64-unknown-linux-gnu)
serde: 1.0.147
serde_yaml: 0.9.14
XiaoXiaoSN, EdJoPaTo, zicklag, mo8it, luben and 2 more