Added error-chain to the config files
This commit is contained in:
parent
6761442241
commit
0f93cd002b
|
@ -1,5 +1,6 @@
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use errors::*;
|
||||||
|
|
||||||
/// The JSON configuration is **deprecated** and will be removed in the near future.
|
/// The JSON configuration is **deprecated** and will be removed in the near future.
|
||||||
/// Please migrate to the TOML configuration.
|
/// Please migrate to the TOML configuration.
|
||||||
|
@ -32,9 +33,9 @@ pub struct JsonConfig {
|
||||||
/// assert_eq!(config.dest, Some(PathBuf::from("htmlbook")));
|
/// assert_eq!(config.dest, Some(PathBuf::from("htmlbook")));
|
||||||
/// ```
|
/// ```
|
||||||
impl JsonConfig {
|
impl JsonConfig {
|
||||||
pub fn from_json(input: &str) -> Result<Self, String> {
|
pub fn from_json(input: &str) -> Result<Self> {
|
||||||
let config: JsonConfig = serde_json::from_str(input)
|
let config: JsonConfig = serde_json::from_str(input)
|
||||||
.map_err(|e| format!("Could not parse JSON: {}", e))?;
|
.chain_err(|| format!("Could not parse JSON"))?;
|
||||||
|
|
||||||
return Ok(config);
|
return Ok(config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use errors::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct TomlConfig {
|
pub struct TomlConfig {
|
||||||
|
@ -43,9 +44,9 @@ pub struct TomlHtmlConfig {
|
||||||
/// assert_eq!(config.output.unwrap().html.unwrap().destination, Some(PathBuf::from("htmlbook")));
|
/// assert_eq!(config.output.unwrap().html.unwrap().destination, Some(PathBuf::from("htmlbook")));
|
||||||
/// ```
|
/// ```
|
||||||
impl TomlConfig {
|
impl TomlConfig {
|
||||||
pub fn from_toml(input: &str) -> Result<Self, String> {
|
pub fn from_toml(input: &str) -> Result<Self> {
|
||||||
let config: TomlConfig = toml::from_str(input)
|
let config: TomlConfig = toml::from_str(input)
|
||||||
.map_err(|e| format!("Could not parse TOML: {}", e))?;
|
.chain_err(|| "Could not parse TOML")?;
|
||||||
|
|
||||||
return Ok(config);
|
return Ok(config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue