arcnmx / serde-ini

Windows INI file {de,}serialization
MIT License
19 stars 17 forks source link

Support parsing duplicate sections to Vec<T> #19

Open Zerowalker opened 2 years ago

Zerowalker commented 2 years ago

As far as i can tell it's not supported.

Here's an example:

struct User{
    #[serde(rename = "Name")]
    name: String,
}

struct Users{
    #[serde(rename = "User")]
    user: Vec<User>,
};

let raw = r#"
[User]
Name=Foo
[User]
Name=Bar
"#;
// Not supported cause of Vec, but not using Vec makes it fail (accurately) cause of duplicate sections
let data: Users = serde_ini::from_str(&raw).unwrap();
arcnmx commented 2 years ago

fwiw master currently has a similar example that deserializes to a top-level Vec, but the feature is incomplete and unreleased.

Zerowalker commented 2 years ago

Ah indeed it does, so this was a bit unnecessary of me bringing it up i guess;P

arcnmx commented 2 years ago

Even so, it seems reasonable to expect your example to work. This is also related to allowing duplicate keys to be {de,}serialized as a vec.

Zerowalker commented 2 years ago

But the feature was incomplete right? so if the example you linked doesn't work, it make sense my doesn't work, or did i misunderstand you?

arcnmx commented 2 years ago

But the feature was incomplete right?

The example in master is incomplete because it can only deserialize. Serialization fails because it is not implemented.

so if the example you linked doesn't work, it make sense my doesn't work

The example linked does work, but its approach differs from yours (uses a top-level vec of an enum instead of a top-level map with a vec field). I'm pretty sure your code still does not work.