When trying to deserialize a struct which contains another struct with the #[serde(flatten)] annotation and a field with the #[serde(flatten)] annotation and the type toml::Value (same with serde_yaml or serde_json), serde will panic.
A minimal example for reproducing this:
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate toml;
#[derive(Debug, Deserialize)]
struct Test {
text: Option<String>,
#[serde(flatten)]
settings: Settings,
#[serde(flatten)]
extra: toml::Value,
}
#[derive(Debug, Deserialize)]
struct Settings {
width: Option<u8>,
}
fn main() {
let file = "text = \"test\"\nwidth = 8";
let test: Test = toml::from_str(file).unwrap();
}
playground
This will result in the following error:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'
When trying to deserialize a struct which contains another struct with the
#[serde(flatten)]annotation and a field with the#[serde(flatten)]annotation and the typetoml::Value(same withserde_yamlorserde_json), serde will panic.A minimal example for reproducing this:
playground
This will result in the following error: