Hello.
I would like deserialize a yaml to the Vec.
#[derive(Debug, Deserialize)]
struct Data {
#[serde(deserialize_with = "deserialize_enum")]
fields: Vec<EnumValue>,
}
#[derive(Debug, Serialize, Deserialize, Eq)]
struct EnumValue
{
id: String,
value: u8, // enum value: 0..255
description: String,
}
YAML:
fields:
- id: FAKE
value: 0
description: Reserve;
https://play.integer32.com/?version=stable&mode=debug&edition=2015&gist=6c6336f1e34016ff2cd25301a140553c
Ultimately I want to have an index from Vector in the value field.
fields:
- id: FAKE
description: foo
- id: FAKE2
description: bar
Data { fields: [
EnumValue { id: "FAKE", value: 0, description: "foo" },
EnumValue { id: "FAKE2", value: 1, description: "bar" },
] }
So something like this? Rust Playground
1 Like
system
closed
#5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.