diff options
author | Ryan Leckey <ryan@launchbadge.com> | 2017-06-22 15:57:14 -0700 |
---|---|---|
committer | Ryan Leckey <ryan@launchbadge.com> | 2017-06-22 15:57:14 -0700 |
commit | 159bb52c595384fed44a2c669198d50f2a758a9a (patch) | |
tree | 6553ceed3e172115fe8e682bbfc286bf8fd0f004 /src/file/format | |
parent | a9eecf075cf01f15ef05fea3f1edaa189446d055 (diff) |
Remove `namespace` option for File
Diffstat (limited to 'src/file/format')
-rw-r--r-- | src/file/format/json.rs | 25 | ||||
-rw-r--r-- | src/file/format/mod.rs | 9 | ||||
-rw-r--r-- | src/file/format/toml.rs | 25 | ||||
-rw-r--r-- | src/file/format/yaml.rs | 26 |
4 files changed, 11 insertions, 74 deletions
diff --git a/src/file/format/json.rs b/src/file/format/json.rs index 290e17d..ed6c787 100644 --- a/src/file/format/json.rs +++ b/src/file/format/json.rs @@ -4,31 +4,10 @@ use std::collections::HashMap; use std::error::Error; use value::{Value, ValueKind}; -pub fn parse(uri: Option<&String>, - text: &str, - namespace: Option<&String>) - -> Result<HashMap<String, Value>, Box<Error>> { +pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error>> { // Parse a JSON object value from the text - let mut root: serde_json::Value = serde_json::from_str(text)?; - - // Limit to namespace - if let Some(namespace) = namespace { - root = serde_json::Value::Object(match root { - serde_json::Value::Object(ref mut table) => { - if let Some(serde_json::Value::Object(table)) = - table.remove(namespace) { - table - } else { - serde_json::Map::new() - } - } - - _ => serde_json::Map::new(), - }); - }; - // TODO: Have a proper error fire if the root of a file is ever not a Table - let value = from_json_value(uri, &root); + let value = from_json_value(uri, &serde_json::from_str(text)?); match value.kind { ValueKind::Table(map) => Ok(map), diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs index 3fc15a6..1988513 100644 --- a/src/file/format/mod.rs +++ b/src/file/format/mod.rs @@ -57,18 +57,17 @@ impl FileFormat { #[allow(unused_variables)] pub fn parse(&self, uri: Option<&String>, - text: &str, - namespace: Option<&String>) + text: &str) -> Result<HashMap<String, Value>, Box<Error>> { match *self { #[cfg(feature = "toml")] - FileFormat::Toml => toml::parse(uri, text, namespace), + FileFormat::Toml => toml::parse(uri, text), #[cfg(feature = "json")] - FileFormat::Json => json::parse(uri, text, namespace), + FileFormat::Json => json::parse(uri, text), #[cfg(feature = "yaml")] - FileFormat::Yaml => yaml::parse(uri, text, namespace), + FileFormat::Yaml => yaml::parse(uri, text), } } } diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs index 2df1fca..6c835a4 100644 --- a/src/file/format/toml.rs +++ b/src/file/format/toml.rs @@ -4,31 +4,10 @@ use std::collections::{HashMap, BTreeMap}; use std::error::Error; use value::{Value, ValueKind}; -pub fn parse(uri: Option<&String>, - text: &str, - namespace: Option<&String>) - -> Result<HashMap<String, Value>, Box<Error>> { +pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error>> { // Parse a TOML value from the provided text - let mut root: toml::Value = toml::from_str(text)?; - - // Limit to namespace - if let Some(namespace) = namespace { - root = toml::Value::Table(match root { - toml::Value::Table(ref mut table) => { - if let Some(toml::Value::Table(table)) = - table.remove(namespace) { - table - } else { - BTreeMap::new() - } - } - - _ => BTreeMap::new(), - }); - } - // TODO: Have a proper error fire if the root of a file is ever not a Table - let value = from_toml_value(uri, &root); + let value = from_toml_value(uri, &toml::from_str(text)?); match value.kind { ValueKind::Table(map) => Ok(map), diff --git a/src/file/format/yaml.rs b/src/file/format/yaml.rs index b1afce7..1cba0d3 100644 --- a/src/file/format/yaml.rs +++ b/src/file/format/yaml.rs @@ -6,14 +6,10 @@ use std::collections::{BTreeMap, HashMap}; use std::mem; use value::{Value, ValueKind}; -pub fn parse(uri: Option<&String>, - text: &str, - namespace: Option<&String>) - -> Result<HashMap<String, Value>, Box<Error>> { +pub fn parse(uri: Option<&String>, text: &str) -> Result<HashMap<String, Value>, Box<Error>> { + // Parse a YAML object from file let mut docs = yaml::YamlLoader::load_from_str(text)?; - - // Designate root - let mut root = match docs.len() { + let root = match docs.len() { 0 => yaml::Yaml::Hash(BTreeMap::new()), 1 => mem::replace(&mut docs[0], yaml::Yaml::Null), n => { @@ -21,22 +17,6 @@ pub fn parse(uri: Option<&String>, } }; - // Limit to namespace - if let Some(namespace) = namespace { - root = yaml::Yaml::Hash(match root { - yaml::Yaml::Hash(ref mut table) => { - if let Some(yaml::Yaml::Hash(table)) = - table.remove(&yaml::Yaml::String(namespace.clone())) { - table - } else { - BTreeMap::new() - } - } - - _ => BTreeMap::new(), - }); - }; - // TODO: Have a proper error fire if the root of a file is ever not a Table let value = from_yaml_value(uri, &root); match value.kind { |