-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Description
Currently we are required to specify at least empty set of parentheses after the enum variant name when deserializing a struct variant which has all fields marked with #[serde(default)].
I find myself converting my unit variants to struct variants and this would make it possible to extend them in a backwards compatible way instead of having to create an empty struct variant from the get go.
Example to illustrate the issue:
use serde::Deserialize;
#[derive(Deserialize)]
enum Foo {
A,
B {
#[serde(default)]
field: String,
}
}
fn main() {
let a: Result<Foo, _> = ron::de::from_str("A");
let b: Result<Foo, _> = ron::de::from_str(r#"B(field: "value")"#);
let c: Result<Foo, _> = ron::de::from_str("B()");
let d: Result<Foo, _> = ron::de::from_str("B");
assert!(a.is_ok()); // Ok
assert!(b.is_ok()); // Ok
assert!(c.is_ok()); // Ok
assert!(d.is_ok()); // Not Ok
}Would it be possible to make the option d deserialize with default values in the same fashion as option c does?
Metadata
Metadata
Assignees
Labels
No labels