summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-29 15:13:00 +0100
committerGitHub <noreply@github.com>2021-12-29 15:13:00 +0100
commit58ac61364293e67755bd0a88c35723a0ef82afd4 (patch)
treea7d6b9e7ef72ff27eb93424b26584c71a7004b1d
parent918c52eb1583b5c895333218f1bb3b4ec24130dd (diff)
parent8420278808b0e97c262cb8bb389a7dc6862dddc7 (diff)
Merge pull request #264 from danieleades/refactor/pedantic-lints
Refactor/pedantic lints
-rw-r--r--src/builder.rs8
-rw-r--r--src/config.rs6
-rw-r--r--src/de.rs4
-rw-r--r--src/env.rs2
-rw-r--r--src/error.rs6
-rw-r--r--src/file/mod.rs2
-rw-r--r--src/file/source/file.rs41
-rw-r--r--src/path/mod.rs34
-rw-r--r--src/ser.rs2
-rw-r--r--src/source.rs2
-rw-r--r--src/value.rs2
11 files changed, 52 insertions, 57 deletions
diff --git a/src/builder.rs b/src/builder.rs
index 4942b47..b641560 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -249,7 +249,7 @@ impl ConfigBuilder<DefaultState> {
let mut cache: Value = Map::<String, Value>::new().into();
// Add defaults
- for (key, val) in defaults.into_iter() {
+ for (key, val) in defaults {
key.set(&mut cache, val);
}
@@ -257,7 +257,7 @@ impl ConfigBuilder<DefaultState> {
sources.collect_to(&mut cache)?;
// Add overrides
- for (key, val) in overrides.into_iter() {
+ for (key, val) in overrides {
key.set(&mut cache, val);
}
@@ -329,7 +329,7 @@ impl ConfigBuilder<AsyncState> {
let mut cache: Value = Map::<String, Value>::new().into();
// Add defaults
- for (key, val) in defaults.into_iter() {
+ for (key, val) in defaults {
key.set(&mut cache, val);
}
@@ -341,7 +341,7 @@ impl ConfigBuilder<AsyncState> {
}
// Add overrides
- for (key, val) in overrides.into_iter() {
+ for (key, val) in overrides {
key.set(&mut cache, val);
}
diff --git a/src/config.rs b/src/config.rs
index 864c0ec..e003daa 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -4,7 +4,7 @@ use crate::builder::{ConfigBuilder, DefaultState};
use serde::de::Deserialize;
use serde::ser::Serialize;
-use crate::error::*;
+use crate::error::{ConfigError, Result};
use crate::map::Map;
use crate::path;
use crate::ser::ConfigSerializer;
@@ -86,7 +86,7 @@ impl Config {
let mut cache: Value = Map::<String, Value>::new().into();
// Add defaults
- for (key, val) in self.defaults.iter() {
+ for (key, val) in &self.defaults {
key.set(&mut cache, val.clone());
}
@@ -94,7 +94,7 @@ impl Config {
self.sources.collect_to(&mut cache)?;
// Add overrides
- for (key, val) in self.overrides.iter() {
+ for (key, val) in &self.overrides {
key.set(&mut cache, val.clone());
}
diff --git a/src/de.rs b/src/de.rs
index dcc1db8..2d5722d 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -4,7 +4,7 @@ use std::iter::Enumerate;
use serde::de;
use crate::config::Config;
-use crate::error::*;
+use crate::error::{ConfigError, Result};
use crate::map::Map;
use crate::value::{Table, Value, ValueKind};
@@ -232,7 +232,7 @@ impl<'de> de::MapAccess<'de> for MapAccess {
V: de::DeserializeSeed<'de>,
{
let (key, value) = self.elements.pop_front().unwrap();
- de::DeserializeSeed::deserialize(seed, value).map_err(|e| e.prepend_key(key))
+ de::DeserializeSeed::deserialize(seed, value).map_err(|e| e.prepend_key(&key))
}
}
diff --git a/src/env.rs b/src/env.rs
index 065c36b..17c706f 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -1,6 +1,6 @@
use std::env;
-use crate::error::*;
+use crate::error::Result;
use crate::map::Map;
use crate::source::Source;
use crate::value::{Value, ValueKind};
diff --git a/src/error.rs b/src/error.rs
index 83ee416..46dc47f 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -134,7 +134,7 @@ impl ConfigError {
}
#[must_use]
- fn prepend(self, segment: String, add_dot: bool) -> Self {
+ fn prepend(self, segment: &str, add_dot: bool) -> Self {
let concat = |key: Option<String>| {
let key = key.unwrap_or_else(String::new);
let dot = if add_dot && key.as_bytes().get(0).unwrap_or(&b'[') != &b'[' {
@@ -162,13 +162,13 @@ impl ConfigError {
}
#[must_use]
- pub(crate) fn prepend_key(self, key: String) -> Self {
+ pub(crate) fn prepend_key(self, key: &str) -> Self {
self.prepend(key, true)
}
#[must_use]
pub(crate) fn prepend_index(self, idx: usize) -> Self {
- self.prepend(format!("[{}]", idx), false)
+ self.prepend(&format!("[{}]", idx), false)
}
}
diff --git a/src/file/mod.rs b/src/file/mod.rs
index 007c250..d4f3e1a 100644
--- a/src/file/mod.rs
+++ b/src/file/mod.rs
@@ -4,7 +4,7 @@ pub mod source;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
-use crate::error::*;
+use crate::error::{ConfigError, Result};
use crate::map::Map;
use crate::source::Source;
use crate::value::Value;
diff --git a/src/file/source/file.rs b/src/file/source/file.rs
index a27c9d2..eaa771b 100644
--- a/src/file/source/file.rs
+++ b/src/file/source/file.rs
@@ -35,29 +35,28 @@ impl FileSourceFile {
// First check for an _exact_ match
if filename.is_file() {
- return match format_hint {
- Some(format) => Ok((filename, Box::new(format))),
- None => {
- for (format, extensions) in ALL_EXTENSIONS.iter() {
- if extensions.contains(
- &filename
- .extension()
- .unwrap_or_default()
- .to_string_lossy()
- .as_ref(),
- ) {
- return Ok((filename, Box::new(*format)));
- }
+ return if let Some(format) = format_hint {
+ Ok((filename, Box::new(format)))
+ } else {
+ for (format, extensions) in ALL_EXTENSIONS.iter() {
+ if extensions.contains(
+ &filename
+ .extension()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .as_ref(),
+ ) {
+ return Ok((filename, Box::new(*format)));
}
-
- Err(Box::new(io::Error::new(
- io::ErrorKind::NotFound,
- format!(
- "configuration file \"{}\" is not of a registered file format",
- filename.to_string_lossy()
- ),
- )))
}
+
+ Err(Box::new(io::Error::new(
+ io::ErrorKind::NotFound,
+ format!(
+ "configuration file \"{}\" is not of a registered file format",
+ filename.to_string_lossy()
+ ),
+ )))
};
}
diff --git a/src/path/mod.rs b/src/path/mod.rs
index 24a6325..baed000 100644
--- a/src/path/mod.rs
+++ b/src/path/mod.rs
@@ -1,6 +1,6 @@
use std::str::FromStr;
-use crate::error::*;
+use crate::error::{ConfigError, Result};
use crate::map::Map;
use crate::value::{Value, ValueKind};
@@ -128,13 +128,13 @@ impl Expression {
},
Expression::Child(ref expr, ref key) => match expr.get_mut_forcibly(root) {
- Some(value) => match value.kind {
- ValueKind::Table(ref mut map) => Some(
- map.entry(key.clone())
- .or_insert_with(|| Value::new(None, ValueKind::Nil)),
- ),
-
- _ => {
+ Some(value) => {
+ if let ValueKind::Table(ref mut map) = value.kind {
+ Some(
+ map.entry(key.clone())
+ .or_insert_with(|| Value::new(None, ValueKind::Nil)),
+ )
+ } else {
*value = Map::<String, Value>::new().into();
if let ValueKind::Table(ref mut map) = value.kind {
@@ -146,7 +146,7 @@ impl Expression {
unreachable!();
}
}
- },
+ }
_ => None,
},
@@ -221,17 +221,13 @@ impl Expression {
Expression::Child(ref expr, ref key) => {
if let Some(parent) = expr.get_mut_forcibly(root) {
- match parent.kind {
- ValueKind::Table(_) => {
- Expression::Identifier(key.clone()).set(parent, value);
- }
+ if let ValueKind::Table(_) = parent.kind {
+ Expression::Identifier(key.clone()).set(parent, value);
+ } else {
+ // Didn't find a table. Oh well. Make a table and do this anyway
+ *parent = Map::<String, Value>::new().into();
- _ => {
- // Didn't find a table. Oh well. Make a table and do this anyway
- *parent = Map::<String, Value>::new().into();
-
- Expression::Identifier(key.clone()).set(parent, value);
- }
+ Expression::Identifier(key.clone()).set(parent, value);
}
}
}
diff --git a/src/ser.rs b/src/ser.rs
index 72d5b01..9ccf7c7 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -2,7 +2,7 @@ use std::fmt::Display;
use serde::ser;
-use crate::error::*;
+use crate::error::{ConfigError, Result};
use crate::value::{Value, ValueKind};
use crate::Config;
diff --git a/src/source.rs b/src/source.rs
index 69cef56..060657b 100644
--- a/src/source.rs
+++ b/src/source.rs
@@ -3,7 +3,7 @@ use std::str::FromStr;
use async_trait::async_trait;
-use crate::error::*;
+use crate::error::Result;
use crate::map::Map;
use crate::path;
use crate::value::{Value, ValueKind};
diff --git a/src/value.rs b/src/value.rs
index 2a274cb..e403192 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -3,7 +3,7 @@ use std::fmt::Display;
use serde::de::{Deserialize, Deserializer, Visitor};
-use crate::error::*;
+use crate::error::{ConfigError, Result, Unexpected};
use crate::map::Map;
/// Underlying kind of the configuration value.