-
Notifications
You must be signed in to change notification settings - Fork 142
Closed
Labels
Description
The following example deserializes an untagged enum with two variants using ron, serde_json, and serde_yaml. The latter two libraries output the expected result, but RON fails with a "data did not match any variant of untagged enum Either" error.
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Root {
value: Either,
}
#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum Either {
One(One),
Two(Two),
}
#[derive(Debug, Deserialize)]
enum One {
OneA,
OneB,
OneC,
}
#[derive(Debug, Deserialize)]
enum Two {
TwoA,
TwoB,
TwoC,
}
const RON_SRC: &str = "OneA";
const JSON_SRC: &str = "{ \"value\": \"OneA\" }";
const YAML_SRC: &str = "value: OneA";
fn main() {
println!("{:?}", ron::de::from_str::<Either>(RON_SRC)); // Err(Message("data did not match any variant of untagged enum Either"))
println!("{:?}", ron::de::from_str::<One>(RON_SRC)); // Ok(OneA)
println!("{:?}", serde_json::from_str::<Root>(JSON_SRC)); // Ok(Root { value: One(OneA) })
println!("{:?}", serde_yaml::from_str::<Root>(YAML_SRC)); // Ok(Root { value: One(OneA) })
}Defman, kvark, mcobzarenco, toyboot4e, NiklasEi and 3 more