use serde::Deserialize; use serde::Serialize; #[derive(Debug, Serialize, Deserialize)] pub struct Recipe { pub name: String, pub description: Option, #[serde(default)] pub modules: Vec, #[serde(default)] pub packages: Vec, } #[derive(Debug, Serialize, Deserialize)] pub struct Modules { pub name: String, pub version: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct Packages { pub name: String, pub version: Option, } #[test] fn both_ends() { let recipe_works = toml::from_str::( r#" name = "testing" description = "example" modules = [] [[packages]] name = "base" "#, ) .unwrap(); toml::to_string(&recipe_works).unwrap(); let recipe_fails = toml::from_str::( r#" name = "testing" description = "example" packages = [] [[modules]] name = "base" "#, ) .unwrap(); let recipe_toml = toml::Table::try_from(recipe_fails).unwrap(); recipe_toml.to_string(); }