summaryrefslogtreecommitdiffstats
path: root/src/file/format
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
committerRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
commit14224be23dc2f253a240b85214927d97e1160669 (patch)
tree6f5b02b26aef5cf37bb14f32b9048165b67109ce /src/file/format
parent71f4b182d1e56febda64bd620ae0e0f65de333cd (diff)
Remove ConfigResult; close #36
Diffstat (limited to 'src/file/format')
-rw-r--r--src/file/format/json.rs21
-rw-r--r--src/file/format/mod.rs9
-rw-r--r--src/file/format/toml.rs7
-rw-r--r--src/file/format/yaml.rs5
4 files changed, 25 insertions, 17 deletions
diff --git a/src/file/format/json.rs b/src/file/format/json.rs
index ead99f8..caf62f5 100644
--- a/src/file/format/json.rs
+++ b/src/file/format/json.rs
@@ -4,7 +4,10 @@ use std::collections::HashMap;
use std::error::Error;
use value::{Value, ValueKind};
-pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
+pub fn parse(
+ uri: Option<&String>,
+ text: &str,
+) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
// Parse a JSON object value from the text
// TODO: Have a proper error fire if the root of a file is ever not a Table
let value = from_json_value(uri, &serde_json::from_str(text)?);
@@ -19,15 +22,13 @@ fn from_json_value(uri: Option<&String>, value: &serde_json::Value) -> Value {
match *value {
serde_json::Value::String(ref value) => Value::new(uri, ValueKind::String(value.clone())),
- serde_json::Value::Number(ref value) => {
- if let Some(value) = value.as_i64() {
- Value::new(uri, ValueKind::Integer(value))
- } else if let Some(value) = value.as_f64() {
- Value::new(uri, ValueKind::Float(value))
- } else {
- unreachable!();
- }
- }
+ serde_json::Value::Number(ref value) => if let Some(value) = value.as_i64() {
+ Value::new(uri, ValueKind::Integer(value))
+ } else if let Some(value) = value.as_f64() {
+ Value::new(uri, ValueKind::Float(value))
+ } else {
+ unreachable!();
+ },
serde_json::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs
index 5aa1acb..a90dfda 100644
--- a/src/file/format/mod.rs
+++ b/src/file/format/mod.rs
@@ -63,10 +63,11 @@ impl FileFormat {
// TODO: pub(crate)
#[doc(hidden)]
#[allow(unused_variables)]
- pub fn parse(&self,
- uri: Option<&String>,
- text: &str)
- -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
+ pub fn parse(
+ &self,
+ uri: Option<&String>,
+ text: &str,
+ ) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
match *self {
#[cfg(feature = "toml")]
FileFormat::Toml => toml::parse(uri, text),
diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs
index 4307e48..9977126 100644
--- a/src/file/format/toml.rs
+++ b/src/file/format/toml.rs
@@ -1,10 +1,13 @@
use toml;
use source::Source;
-use std::collections::{HashMap, BTreeMap};
+use std::collections::{BTreeMap, HashMap};
use std::error::Error;
use value::{Value, ValueKind};
-pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
+pub fn parse(
+ uri: Option<&String>,
+ text: &str,
+) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
// Parse a TOML value from the provided text
// TODO: Have a proper error fire if the root of a file is ever not a Table
let value = from_toml_value(uri, &toml::from_str(text)?);
diff --git a/src/file/format/yaml.rs b/src/file/format/yaml.rs
index 9bcf9d4..87240ac 100644
--- a/src/file/format/yaml.rs
+++ b/src/file/format/yaml.rs
@@ -6,7 +6,10 @@ use std::collections::HashMap;
use std::mem;
use value::{Value, ValueKind};
-pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
+pub fn parse(
+ uri: Option<&String>,
+ text: &str,
+) -> Result<HashMap<String, Value>, Box<Error + Send + Sync>> {
// Parse a YAML object from file
let mut docs = yaml::YamlLoader::load_from_str(text)?;
let root = match docs.len() {