extern crate toml; use std::path::PathBuf; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlConfig { pub source: Option, pub title: Option, pub author: Option, pub authors: Option>, pub description: Option, pub output: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlOutputConfig { pub html: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlHtmlConfig { pub destination: Option, pub theme: Option, pub google_analytics: Option, } /// Returns a TomlConfig from a TOML string /// /// ``` /// # use mdbook::config::tomlconfig::TomlConfig; /// # use std::path::PathBuf; /// let toml = r#"title="Some title" /// [output.html] /// destination = "htmlbook" "#; /// /// let config = TomlConfig::from_toml(&toml).expect("Should parse correctly"); /// assert_eq!(config.title, Some(String::from("Some title"))); /// assert_eq!(config.output.unwrap().html.unwrap().destination, Some(PathBuf::from("htmlbook"))); /// ``` impl TomlConfig { pub fn from_toml(input: &str) -> Result { let config: TomlConfig = toml::from_str(input) .map_err(|e| format!("Could not parse TOML: {}", e))?; return Ok(config); } }