summaryrefslogtreecommitdiffstats
path: root/src/file
diff options
context:
space:
mode:
authorDavid Orchard <if_coding@fastmail.com>2021-08-01 00:03:10 -0700
committerDavid Orchard <if_coding@fastmail.com>2021-08-15 10:31:58 -0700
commitcc0530a7716779f954b1756905a9f4ceb7eb6d62 (patch)
tree311b2ca44a282bbc629a08123f53a855cba38c1c /src/file
parent622efaca17256fb42dafc61c8df1f3037c1fb772 (diff)
Move order preservation under a feature gate
Diffstat (limited to 'src/file')
-rw-r--r--src/file/format/hjson.rs8
-rw-r--r--src/file/format/ini.rs8
-rw-r--r--src/file/format/json.rs8
-rw-r--r--src/file/format/json5.rs8
-rw-r--r--src/file/format/mod.rs8
-rw-r--r--src/file/format/ron.rs8
-rw-r--r--src/file/format/toml.rs8
-rw-r--r--src/file/format/yaml.rs8
-rw-r--r--src/file/mod.rs6
9 files changed, 35 insertions, 35 deletions
diff --git a/src/file/format/hjson.rs b/src/file/format/hjson.rs
index a61afef..68b9c9c 100644
--- a/src/file/format/hjson.rs
+++ b/src/file/format/hjson.rs
@@ -1,19 +1,19 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn 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_hjson_value(uri, &serde_hjson::from_str(text)?);
match value.kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
}
}
@@ -30,7 +30,7 @@ fn from_hjson_value(uri: Option<&String>, value: &serde_hjson::Value) -> Value {
serde_hjson::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
serde_hjson::Value::Object(ref table) => {
- let mut m = LinkedHashMap::new();
+ let mut m = MapImpl::new();
for (key, value) in table {
m.insert(key.clone(), from_hjson_value(uri, value));
diff --git a/src/file/format/ini.rs b/src/file/format/ini.rs
index 47f3499..b5f742d 100644
--- a/src/file/format/ini.rs
+++ b/src/file/format/ini.rs
@@ -1,20 +1,20 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
use ini::Ini;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
- let mut map: LinkedHashMap<String, Value> = LinkedHashMap::new();
+) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> {
+ let mut map: MapImpl<String, Value> = MapImpl::new();
let i = Ini::load_from_str(text)?;
for (sec, prop) in i.iter() {
match sec {
Some(sec) => {
- let mut sec_map: LinkedHashMap<String, Value> = LinkedHashMap::new();
+ let mut sec_map: MapImpl<String, Value> = MapImpl::new();
for (k, v) in prop.iter() {
sec_map.insert(
k.to_owned(),
diff --git a/src/file/format/json.rs b/src/file/format/json.rs
index a6a9443..c4895fb 100644
--- a/src/file/format/json.rs
+++ b/src/file/format/json.rs
@@ -1,19 +1,19 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn 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)?);
match value.kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
}
}
@@ -34,7 +34,7 @@ fn from_json_value(uri: Option<&String>, value: &serde_json::Value) -> Value {
serde_json::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
serde_json::Value::Object(ref table) => {
- let mut m = LinkedHashMap::new();
+ let mut m = MapImpl::new();
for (key, value) in table {
m.insert(key.clone(), from_json_value(uri, value));
diff --git a/src/file/format/json5.rs b/src/file/format/json5.rs
index 952b265..69432c0 100644
--- a/src/file/format/json5.rs
+++ b/src/file/format/json5.rs
@@ -1,7 +1,7 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
use crate::error::{ConfigError, Unexpected};
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
#[derive(serde::Deserialize, Debug)]
@@ -13,13 +13,13 @@ pub enum Val {
Float(f64),
String(String),
Array(Vec<Val>),
- Object(LinkedHashMap<String, Val>),
+ Object(MapImpl<String, Val>),
}
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> {
match json5_rs::from_str::<Val>(text)? {
Val::String(ref value) => Err(Unexpected::Str(value.clone())),
Val::Integer(value) => Err(Unexpected::Integer(value)),
@@ -29,7 +29,7 @@ pub fn parse(
Val::Null => Err(Unexpected::Unit),
Val::Object(o) => match from_json5_value(uri, Val::Object(o)).kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
},
}
.map_err(|err| ConfigError::invalid_root(uri, err))
diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs
index 55d1c7a..df59ca6 100644
--- a/src/file/format/mod.rs
+++ b/src/file/format/mod.rs
@@ -2,9 +2,9 @@
// BUG: ? For some reason this doesn't do anything if I try and function scope this
#![allow(unused_mut)]
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
+use crate::map::MapImpl;
use crate::value::Value;
#[cfg(feature = "toml")]
@@ -62,8 +62,8 @@ pub enum FileFormat {
lazy_static! {
#[doc(hidden)]
// #[allow(unused_mut)] ?
- pub static ref ALL_EXTENSIONS: LinkedHashMap<FileFormat, Vec<&'static str>> = {
- let mut formats: LinkedHashMap<FileFormat, Vec<_>> = LinkedHashMap::new();
+ pub static ref ALL_EXTENSIONS: MapImpl<FileFormat, Vec<&'static str>> = {
+ let mut formats: MapImpl<FileFormat, Vec<_>> = MapImpl::new();
#[cfg(feature = "toml")]
formats.insert(FileFormat::Toml, vec!["toml"]);
@@ -107,7 +107,7 @@ impl FileFormat {
self,
uri: Option<&String>,
text: &str,
- ) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+ ) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> {
match self {
#[cfg(feature = "toml")]
FileFormat::Toml => toml::parse(uri, text),
diff --git a/src/file/format/ron.rs b/src/file/format/ron.rs
index a527d6f..769fd53 100644
--- a/src/file/format/ron.rs
+++ b/src/file/format/ron.rs
@@ -1,17 +1,17 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> {
let value = from_ron_value(uri, ron::from_str(text)?)?;
match value.kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
}
}
@@ -56,7 +56,7 @@ fn from_ron_value(
Ok((key, value))
})
- .collect::<Result<LinkedHashMap<_, _>, _>>()?;
+ .collect::<Result<MapImpl<_, _>, _>>()?;
ValueKind::Table(map)
}
diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs
index 5468d97..a4e16b2 100644
--- a/src/file/format/toml.rs
+++ b/src/file/format/toml.rs
@@ -1,19 +1,19 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn 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)?);
match value.kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
}
}
@@ -25,7 +25,7 @@ fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value {
toml::Value::Boolean(value) => Value::new(uri, value),
toml::Value::Table(ref table) => {
- let mut m = LinkedHashMap::new();
+ let mut m = MapImpl::new();
for (key, value) in table {
m.insert(key.clone(), from_toml_value(uri, value));
diff --git a/src/file/format/yaml.rs b/src/file/format/yaml.rs
index 246758a..f725b1f 100644
--- a/src/file/format/yaml.rs
+++ b/src/file/format/yaml.rs
@@ -1,16 +1,16 @@
-use linked_hash_map::LinkedHashMap;
use std::error::Error;
use std::fmt;
use std::mem;
use yaml_rust as yaml;
+use crate::map::MapImpl;
use crate::value::{Value, ValueKind};
pub fn parse(
uri: Option<&String>,
text: &str,
-) -> Result<LinkedHashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> {
// Parse a YAML object from file
let mut docs = yaml::YamlLoader::load_from_str(text)?;
let root = match docs.len() {
@@ -26,7 +26,7 @@ pub fn parse(
match value.kind {
ValueKind::Table(map) => Ok(map),
- _ => Ok(LinkedHashMap::new()),
+ _ => Ok(MapImpl::new()),
}
}
@@ -40,7 +40,7 @@ fn from_yaml_value(uri: Option<&String>, value: &yaml::Yaml) -> Value {
yaml::Yaml::Integer(value) => Value::new(uri, ValueKind::Integer(value)),
yaml::Yaml::Boolean(value) => Value::new(uri, ValueKind::Boolean(value)),
yaml::Yaml::Hash(ref table) => {
- let mut m = LinkedHashMap::new();
+ let mut m = MapImpl::new();
for (key, value) in table {
if let Some(k) = key.as_str() {
m.insert(k.to_owned(), from_yaml_value(uri, value));
diff --git a/src/file/mod.rs b/src/file/mod.rs
index 02fd51f..d5744f4 100644
--- a/src/file/mod.rs
+++ b/src/file/mod.rs
@@ -1,10 +1,10 @@
mod format;
pub mod source;
-use linked_hash_map::LinkedHashMap;
use std::path::{Path, PathBuf};
use crate::error::*;
+use crate::map::MapImpl;
use crate::source::Source;
use crate::value::Value;
@@ -99,7 +99,7 @@ where
Box::new((*self).clone())
}
- fn collect(&self) -> Result<LinkedHashMap<String, Value>> {
+ fn collect(&self) -> Result<MapImpl<String, Value>> {
// Coerce the file contents to a string
let (uri, contents, format) = match self
.source
@@ -110,7 +110,7 @@ where
Err(error) => {
if !self.required {
- return Ok(LinkedHashMap::new());
+ return Ok(MapImpl::new());
}
return Err(error);