Let says that I have this Yaml:
countries:
cities:
paris:
- street: "ranom_name_1"
weather: 12
pollution: 2
- sreet: "ranom_name_2"
weather: 15
pollution: 1
london:
- street: "ranom_name_1"
weather: 5
pollution: 1
rank: 1
- sreet: "ranom_name_2"
weather: 1
pollution: 4
rank: 2
After I made the needed structures :
#[derive(Debug, Deserialize)]
struct Paris {
street: String,
weather: u16,
pollution: u16,
}
#[derive(Debug, Deserialize)]
struct London {
street: String,
weather: u16,
pollution: u16,
rank: u16,
}
#[derive(Debug, Deserialize)]
struct Cities {
#[serde(flatten)]
paris: Vec<Paris>,
#[serde(flatten)]
london: Vec<London>,
}
#[derive(Debug, Deserialize)]
struct Country {
#[serde(flatten)]
cities: Cities,
}
pub struct Data {
#[serde(flatten)]
coutries: Country,
}
The problem is that serde can't flatten Vec, so when I call :
let data = serde_yaml::from_str::<Data>(data_yaml);
I get this error :
Error : can only flatten structs and maps at line 3 column 7
My question is, how can I deserialize my Yaml ?