1 use serde::Deserialize;
2 use serde::Serialize;
3
4 #[derive(Debug, Serialize, Deserialize)]
5 pub struct Recipe {
6 pub name: String,
7 pub description: Option<String>,
8 #[serde(default)]
9 pub modules: Vec<Modules>,
10 #[serde(default)]
11 pub packages: Vec<Packages>,
12 }
13
14 #[derive(Debug, Serialize, Deserialize)]
15 pub struct Modules {
16 pub name: String,
17 pub version: Option<String>,
18 }
19
20 #[derive(Debug, Serialize, Deserialize)]
21 pub struct Packages {
22 pub name: String,
23 pub version: Option<String>,
24 }
25
26 #[test]
both_ends()27 fn both_ends() {
28 let recipe_works = toml::from_str::<Recipe>(
29 r#"
30 name = "testing"
31 description = "example"
32 modules = []
33
34 [[packages]]
35 name = "base"
36 "#,
37 )
38 .unwrap();
39 toml::to_string(&recipe_works).unwrap();
40
41 let recipe_fails = toml::from_str::<Recipe>(
42 r#"
43 name = "testing"
44 description = "example"
45 packages = []
46
47 [[modules]]
48 name = "base"
49 "#,
50 )
51 .unwrap();
52
53 let recipe_toml = toml::Table::try_from(recipe_fails).unwrap();
54 recipe_toml.to_string();
55 }
56