diff options
author | David Orchard <if_coding@fastmail.com> | 2021-08-02 23:17:08 -0700 |
---|---|---|
committer | David Orchard <if_coding@fastmail.com> | 2021-08-15 10:34:05 -0700 |
commit | be82af2a474b9c6ac85ec1e001af1704521820e6 (patch) | |
tree | b065f9a4adaddfad570b370937e8081cd6fa70ed /src | |
parent | 0e0ae2b359b5c943055c988c3c78f36db2503468 (diff) |
Rename MapImpl to Map
Diffstat (limited to 'src')
-rw-r--r-- | src/builder.rs | 22 | ||||
-rw-r--r-- | src/config.rs | 12 | ||||
-rw-r--r-- | src/de.rs | 4 | ||||
-rw-r--r-- | src/env.rs | 6 | ||||
-rw-r--r-- | src/file/format/hjson.rs | 8 | ||||
-rw-r--r-- | src/file/format/ini.rs | 8 | ||||
-rw-r--r-- | src/file/format/json.rs | 8 | ||||
-rw-r--r-- | src/file/format/json5.rs | 8 | ||||
-rw-r--r-- | src/file/format/mod.rs | 4 | ||||
-rw-r--r-- | src/file/format/ron.rs | 8 | ||||
-rw-r--r-- | src/file/format/toml.rs | 8 | ||||
-rw-r--r-- | src/file/format/yaml.rs | 8 | ||||
-rw-r--r-- | src/file/mod.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/map.rs | 4 | ||||
-rw-r--r-- | src/path/mod.rs | 10 | ||||
-rw-r--r-- | src/source.rs | 22 | ||||
-rw-r--r-- | src/value.rs | 10 |
18 files changed, 79 insertions, 79 deletions
diff --git a/src/builder.rs b/src/builder.rs index 0cbd32a..e629606 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -2,7 +2,7 @@ use std::iter::IntoIterator; use std::str::FromStr; use crate::error::Result; -use crate::map::MapImpl; +use crate::map::Map; use crate::source::AsyncSource; use crate::{config::Config, path::Expression, source::Source, value::Value}; @@ -88,8 +88,8 @@ use crate::{config::Config, path::Expression, source::Source, value::Value}; /// ``` #[derive(Debug, Clone, Default)] pub struct ConfigBuilder<St: BuilderState> { - defaults: MapImpl<Expression, Value>, - overrides: MapImpl<Expression, Value>, + defaults: Map<Expression, Value>, + overrides: Map<Expression, Value>, state: St, } @@ -121,8 +121,8 @@ pub struct DefaultState { /// Refer to [`ConfigBuilder`] for similar API sample usage or to the examples folder of the crate, where such a source is implemented. #[derive(Debug, Clone, Default)] pub struct AsyncConfigBuilder { - defaults: MapImpl<Expression, Value>, - overrides: MapImpl<Expression, Value>, + defaults: Map<Expression, Value>, + overrides: Map<Expression, Value>, sources: Vec<SourceType>, } @@ -245,11 +245,11 @@ impl ConfigBuilder<DefaultState> { } fn build_internal( - defaults: MapImpl<Expression, Value>, - overrides: MapImpl<Expression, Value>, + defaults: Map<Expression, Value>, + overrides: Map<Expression, Value>, sources: &[Box<dyn Source + Send + Sync>], ) -> Result<Config> { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + let mut cache: Value = Map::<String, Value>::new().into(); // Add defaults for (key, val) in defaults.into_iter() { @@ -323,11 +323,11 @@ impl ConfigBuilder<AsyncState> { } async fn build_internal( - defaults: MapImpl<Expression, Value>, - overrides: MapImpl<Expression, Value>, + defaults: Map<Expression, Value>, + overrides: Map<Expression, Value>, sources: &[SourceType], ) -> Result<Config> { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + let mut cache: Value = Map::<String, Value>::new().into(); // Add defaults for (key, val) in defaults.into_iter() { diff --git a/src/config.rs b/src/config.rs index 8c410f0..55844ce 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,7 @@ use serde::de::Deserialize; use serde::ser::Serialize; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::path; use crate::ser::ConfigSerializer; use crate::source::Source; @@ -16,8 +16,8 @@ use crate::value::{Table, Value}; /// them according to the source's priority. #[derive(Clone, Debug)] pub struct Config { - defaults: MapImpl<path::Expression, Value>, - overrides: MapImpl<path::Expression, Value>, + defaults: Map<path::Expression, Value>, + overrides: Map<path::Expression, Value>, sources: Vec<Box<dyn Source + Send + Sync>>, /// Root of the cached configuration. @@ -83,7 +83,7 @@ impl Config { #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")] pub fn refresh(&mut self) -> Result<&mut Config> { self.cache = { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + let mut cache: Value = Map::<String, Value>::new().into(); // Add defaults for (key, val) in self.defaults.iter() { @@ -181,7 +181,7 @@ impl Config { self.get(key).and_then(Value::into_bool) } - pub fn get_table(&self, key: &str) -> Result<MapImpl<String, Value>> { + pub fn get_table(&self, key: &str) -> Result<Map<String, Value>> { self.get(key).and_then(Value::into_table) } @@ -212,7 +212,7 @@ impl Source for Config { Box::new((*self).clone()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { + fn collect(&self) -> Result<Map<String, Value>> { self.cache.clone().into_table() } } @@ -5,7 +5,7 @@ use serde::de; use crate::config::Config; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Table, Value, ValueKind}; impl<'de> de::Deserializer<'de> for Value { @@ -200,7 +200,7 @@ struct MapAccess { } impl MapAccess { - fn new(table: MapImpl<String, Value>) -> Self { + fn new(table: Map<String, Value>) -> Self { MapAccess { elements: table.into_iter().collect(), } @@ -1,7 +1,7 @@ use std::env; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::source::Source; use crate::value::{Value, ValueKind}; @@ -79,8 +79,8 @@ impl Source for Environment { Box::new((*self).clone()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { - let mut m = MapImpl::new(); + fn collect(&self) -> Result<Map<String, Value>> { + let mut m = Map::new(); let uri: String = "the environment".into(); let separator = self.separator.as_deref().unwrap_or(""); diff --git a/src/file/format/hjson.rs b/src/file/format/hjson.rs index 68b9c9c..4b76114 100644 --- a/src/file/format/hjson.rs +++ b/src/file/format/hjson.rs @@ -1,19 +1,19 @@ use std::error::Error; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::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 = MapImpl::new(); + let mut m = Map::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 b5f742d..9295e60 100644 --- a/src/file/format/ini.rs +++ b/src/file/format/ini.rs @@ -2,19 +2,19 @@ use std::error::Error; use ini::Ini; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { - let mut map: MapImpl<String, Value> = MapImpl::new(); +) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> { + let mut map: Map<String, Value> = Map::new(); let i = Ini::load_from_str(text)?; for (sec, prop) in i.iter() { match sec { Some(sec) => { - let mut sec_map: MapImpl<String, Value> = MapImpl::new(); + let mut sec_map: Map<String, Value> = Map::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 c4895fb..e3d8b87 100644 --- a/src/file/format/json.rs +++ b/src/file/format/json.rs @@ -1,19 +1,19 @@ use std::error::Error; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::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 = MapImpl::new(); + let mut m = Map::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 69432c0..c156797 100644 --- a/src/file/format/json5.rs +++ b/src/file/format/json5.rs @@ -1,7 +1,7 @@ use std::error::Error; use crate::error::{ConfigError, Unexpected}; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; #[derive(serde::Deserialize, Debug)] @@ -13,13 +13,13 @@ pub enum Val { Float(f64), String(String), Array(Vec<Val>), - Object(MapImpl<String, Val>), + Object(Map<String, Val>), } pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::new()), }, } .map_err(|err| ConfigError::invalid_root(uri, err)) diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs index 640ef28..9f6d7d7 100644 --- a/src/file/format/mod.rs +++ b/src/file/format/mod.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::error::Error; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::Value; #[cfg(feature = "toml")] @@ -108,7 +108,7 @@ impl FileFormat { self, uri: Option<&String>, text: &str, - ) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { + ) -> Result<Map<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 769fd53..3fb2a0f 100644 --- a/src/file/format/ron.rs +++ b/src/file/format/ron.rs @@ -1,17 +1,17 @@ use std::error::Error; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::new()), } } @@ -56,7 +56,7 @@ fn from_ron_value( Ok((key, value)) }) - .collect::<Result<MapImpl<_, _>, _>>()?; + .collect::<Result<Map<_, _>, _>>()?; ValueKind::Table(map) } diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs index a4e16b2..af21fc7 100644 --- a/src/file/format/toml.rs +++ b/src/file/format/toml.rs @@ -1,19 +1,19 @@ use std::error::Error; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::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 = MapImpl::new(); + let mut m = Map::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 f725b1f..44b72fb 100644 --- a/src/file/format/yaml.rs +++ b/src/file/format/yaml.rs @@ -4,13 +4,13 @@ use std::mem; use yaml_rust as yaml; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; pub fn parse( uri: Option<&String>, text: &str, -) -> Result<MapImpl<String, Value>, Box<dyn Error + Send + Sync>> { +) -> Result<Map<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(MapImpl::new()), + _ => Ok(Map::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 = MapImpl::new(); + let mut m = Map::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 d5744f4..0160d7c 100644 --- a/src/file/mod.rs +++ b/src/file/mod.rs @@ -4,7 +4,7 @@ pub mod source; use std::path::{Path, PathBuf}; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::source::Source; use crate::value::Value; @@ -99,7 +99,7 @@ where Box::new((*self).clone()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { + fn collect(&self) -> Result<Map<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(MapImpl::new()); + return Ok(Map::new()); } return Err(error); @@ -71,7 +71,7 @@ pub use crate::config::Config; pub use crate::env::Environment; pub use crate::error::ConfigError; pub use crate::file::{File, FileFormat, FileSourceFile, FileSourceString}; -pub use crate::map::MapImpl; +pub use crate::map::Map; pub use crate::source::AsyncSource; pub use crate::source::Source; pub use crate::value::Value; @@ -1,4 +1,4 @@ #[cfg(not(feature = "preserve_order"))] -pub type MapImpl<K, V> = std::collections::HashMap<K, V>; +pub type Map<K, V> = std::collections::HashMap<K, V>; #[cfg(feature = "preserve_order")] -pub type MapImpl<K, V> = indexmap::IndexMap<K, V>; +pub type Map<K, V> = indexmap::IndexMap<K, V>; diff --git a/src/path/mod.rs b/src/path/mod.rs index 8ce51f9..cd7ccd7 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::value::{Value, ValueKind}; mod parser; @@ -135,7 +135,7 @@ impl Expression { ), _ => { - *value = MapImpl::<String, Value>::new().into(); + *value = Map::<String, Value>::new().into(); if let ValueKind::Table(ref mut map) = value.kind { Some( @@ -186,7 +186,7 @@ impl Expression { ValueKind::Table(_) => {} _ => { - *root = MapImpl::<String, Value>::new().into(); + *root = Map::<String, Value>::new().into(); } } @@ -195,7 +195,7 @@ impl Expression { // Pull out another table let mut target = if let ValueKind::Table(ref mut map) = root.kind { map.entry(id.clone()) - .or_insert_with(|| MapImpl::<String, Value>::new().into()) + .or_insert_with(|| Map::<String, Value>::new().into()) } else { unreachable!(); }; @@ -228,7 +228,7 @@ impl Expression { _ => { // Didn't find a table. Oh well. Make a table and do this anyway - *parent = MapImpl::<String, Value>::new().into(); + *parent = Map::<String, Value>::new().into(); Expression::Identifier(key.clone()).set(parent, value); } diff --git a/src/source.rs b/src/source.rs index 2c76366..0faf6d1 100644 --- a/src/source.rs +++ b/src/source.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use async_trait::async_trait; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; use crate::path; use crate::value::{Value, ValueKind}; @@ -13,8 +13,8 @@ pub trait Source: Debug { fn clone_into_box(&self) -> Box<dyn Source + Send + Sync>; /// Collect all configuration properties available from this source and return - /// a MapImpl. - fn collect(&self) -> Result<MapImpl<String, Value>>; + /// a Map. + fn collect(&self) -> Result<Map<String, Value>>; /// Collects all configuration properties to a provided cache. fn collect_to(&self, cache: &mut Value) -> Result<()> { @@ -55,8 +55,8 @@ pub trait AsyncSource: Debug + Sync { // Sync is supertrait due to https://docs.rs/async-trait/0.1.50/async_trait/index.html#dyn-traits /// Collects all configuration properties available from this source and return - /// a MapImpl as an async operations. - async fn collect(&self) -> Result<MapImpl<String, Value>>; + /// a Map as an async operations. + async fn collect(&self) -> Result<Map<String, Value>>; /// Collects all configuration properties to a provided cache. async fn collect_to(&self, cache: &mut Value) -> Result<()> { @@ -86,8 +86,8 @@ impl Source for Vec<Box<dyn Source + Send + Sync>> { Box::new((*self).clone()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + fn collect(&self) -> Result<Map<String, Value>> { + let mut cache: Value = Map::<String, Value>::new().into(); for source in self { source.collect_to(&mut cache)?; @@ -106,8 +106,8 @@ impl Source for [Box<dyn Source + Send + Sync>] { Box::new(self.to_owned()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + fn collect(&self) -> Result<Map<String, Value>> { + let mut cache: Value = Map::<String, Value>::new().into(); for source in self { source.collect_to(&mut cache)?; @@ -131,8 +131,8 @@ where Box::new((*self).clone()) } - fn collect(&self) -> Result<MapImpl<String, Value>> { - let mut cache: Value = MapImpl::<String, Value>::new().into(); + fn collect(&self) -> Result<Map<String, Value>> { + let mut cache: Value = Map::<String, Value>::new().into(); for source in self { source.collect_to(&mut cache)?; diff --git a/src/value.rs b/src/value.rs index 17be54d..1523c1e 100644 --- a/src/value.rs +++ b/src/value.rs @@ -4,7 +4,7 @@ use std::fmt::Display; use serde::de::{Deserialize, Deserializer, Visitor}; use crate::error::*; -use crate::map::MapImpl; +use crate::map::Map; /// Underlying kind of the configuration value. /// @@ -23,7 +23,7 @@ pub enum ValueKind { } pub type Array = Vec<Value>; -pub type Table = MapImpl<String, Value>; +pub type Table = Map<String, Value>; impl Default for ValueKind { fn default() -> Self { @@ -73,11 +73,11 @@ impl From<bool> for ValueKind { } } -impl<T> From<MapImpl<String, T>> for ValueKind +impl<T> From<Map<String, T>> for ValueKind where T: Into<Value>, { - fn from(values: MapImpl<String, T>) -> Self { + fn from(values: Map<String, T>) -> Self { let t = values.into_iter().map(|(k, v)| (k, v.into())).collect(); ValueKind::Table(t) } @@ -357,7 +357,7 @@ impl Value { /// If the `Value` is a Table, returns the associated Map. // FIXME: Should this not be `try_into_*` ? - pub fn into_table(self) -> Result<MapImpl<String, Value>> { + pub fn into_table(self) -> Result<Map<String, Value>> { match self.kind { ValueKind::Table(value) => Ok(value), |