-
Notifications
You must be signed in to change notification settings - Fork 136
Closed
Description
Trying to roundtrip this type Rust-RON-Rust:
#[derive(Debug, Serialize, Deserialize)]
enum InnerEnum {
UnitVariant,
}
#[derive(Debug, Serialize, Deserialize)]
struct Container {
field: InnerEnum,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "tag")]
enum OuterEnum { // <- this type
Variant(Container),
}
gives the following RON:
(
tag: "Variant",
field: UnitVariant,
)
which produces the following error when trying to deserialize it:
4:2: Expected string or map but found a unit value instead
(playground-ish)
Some notes:
- Deserialization to
ron::Value
reveals that the variant of theInnerEnum
is lost and replaced withUnit
. - The error location is particularly unhelpful: it points to the end of the file.
Full repro code duplicated here for resillience
/*
[dependencies]
serde = { version = "1", features = ["derive"] }
ron = "=0.8.0"
*/
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
enum InnerEnum {
UnitVariant,
}
#[derive(Debug, Serialize, Deserialize)]
struct Container {
field: InnerEnum,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "tag")]
enum OuterEnum {
Variant(Container),
}
fn main() -> Result<(), ron::Error> {
let value = OuterEnum::Variant(Container {
field: InnerEnum::UnitVariant,
});
let serialized = ron::ser::to_string_pretty(&value, <_>::default())?;
println!("--- serialized ---\n{serialized}\n");
let ron_value: ron::Value = ron::from_str(&serialized)?;
println!("--- deserialized as ron::Value ---\n{ron_value:#?}\n");
let err = ron::from_str::<OuterEnum>(&serialized).unwrap_err();
println!("--- deserialization error ---\n{err}");
Ok(())
}
Possibly related to #217, but doesn’t use neither untagged nor externally tagged enums.