-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config_parse.rs
More file actions
40 lines (36 loc) · 1.06 KB
/
test_config_parse.rs
File metadata and controls
40 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SiteData {
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub description: Option<String>,
#[serde(default)]
pub author: Option<serde_yaml::Value>,
#[serde(flatten)]
pub custom: HashMap<String, serde_yaml::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Config {
pub title: Option<String>,
pub description: Option<String>,
pub author: Option<serde_yaml::Value>,
#[serde(default)]
pub site_data: SiteData,
#[serde(flatten)]
pub custom: HashMap<String, serde_yaml::Value>,
}
fn main() {
let yaml = r#"
title: Rustyll Demo Site
description: A demonstration
author:
name: Rustyll Team
email: hello@rustyll.dev
"#;
let config: Config = serde_yaml::from_str(yaml).unwrap();
println!("Config: {:#?}", config);
println!("Top-level author: {:?}", config.author);
println!("site_data.author: {:?}", config.site_data.author);
}