summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadosław Kot <rdkt13@gmail.com>2021-10-17 09:36:12 +0200
committerRadosław Kot <rdkt13@gmail.com>2021-10-23 16:58:41 +0200
commit5ba9013b425b2d54b56a0f67149ceb2c50781638 (patch)
tree1754a84bef73cde196ba32115d2cb1c68ba02153
parent583a47764a93465ce8d846a6a7273a9bd38fd554 (diff)
Apply clippy lints and format
-rw-r--r--examples/async_source/main.rs10
-rw-r--r--examples/custom_format/main.rs11
-rw-r--r--src/file/format/mod.rs6
-rw-r--r--src/format.rs5
-rw-r--r--src/lib.rs4
5 files changed, 16 insertions, 20 deletions
diff --git a/examples/async_source/main.rs b/examples/async_source/main.rs
index 02f8cd7..f5459b9 100644
--- a/examples/async_source/main.rs
+++ b/examples/async_source/main.rs
@@ -1,6 +1,8 @@
-use std::{collections::HashMap, error::Error, fmt::Debug};
+use std::{error::Error, fmt::Debug};
-use config::{AsyncSource, ConfigBuilder, ConfigError, FileFormat, Format, builder::AsyncState, Map};
+use config::{
+ builder::AsyncState, AsyncSource, ConfigBuilder, ConfigError, FileFormat, Format, Map,
+};
use async_trait::async_trait;
use futures::{select, FutureExt};
@@ -49,13 +51,13 @@ async fn run_client() -> Result<(), Box<dyn Error>> {
// Actual implementation of AsyncSource can be found below
#[derive(Debug)]
-struct HttpSource<F : Format> {
+struct HttpSource<F: Format> {
uri: String,
format: F,
}
#[async_trait]
-impl<F : Format + Send + Sync + Debug> AsyncSource for HttpSource<F> {
+impl<F: Format + Send + Sync + Debug> AsyncSource for HttpSource<F> {
async fn collect(&self) -> Result<Map<String, config::Value>, ConfigError> {
reqwest::get(&self.uri)
.await
diff --git a/examples/custom_format/main.rs b/examples/custom_format/main.rs
index c149436..c21bac2 100644
--- a/examples/custom_format/main.rs
+++ b/examples/custom_format/main.rs
@@ -1,6 +1,4 @@
-use std::collections::HashMap;
-
-use config::{Config, File, FileExtensions, Format, Value, ValueKind};
+use config::{Config, File, FileExtensions, Format, Map, Value, ValueKind};
fn main() {
let config = Config::builder()
@@ -22,15 +20,12 @@ impl Format for MyFormat {
&self,
uri: Option<&String>,
text: &str,
- ) -> Result<
- std::collections::HashMap<String, config::Value>,
- Box<dyn std::error::Error + Send + Sync>,
- > {
+ ) -> Result<Map<String, config::Value>, Box<dyn std::error::Error + Send + Sync>> {
// Let's assume our format is somewhat crippled, but this is fine
// In real life anything can be used here - nom, serde or other.
//
// For some more real-life examples refer to format implementation within the library code
- let mut result = HashMap::new();
+ let mut result = Map::new();
if text == "good" {
result.insert(
diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs
index a335426..d5414f5 100644
--- a/src/file/format/mod.rs
+++ b/src/file/format/mod.rs
@@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::error::Error;
use crate::map::Map;
-use crate::{value::Value, Format, file::extension::FileExtensions};
+use crate::{file::extension::FileExtensions, value::Value, Format};
#[cfg(feature = "toml")]
mod toml;
@@ -85,14 +85,14 @@ lazy_static! {
}
impl FileFormat {
- pub (crate) fn extensions(&self) -> &'static [&'static str] {
+ pub(crate) fn extensions(&self) -> &'static [&'static str] {
// It should not be possible for this to fail
// A FileFormat would need to be declared without being added to the
// ALL_EXTENSIONS map.
ALL_EXTENSIONS.get(self).unwrap()
}
- pub (crate) fn parse(
+ pub(crate) fn parse(
&self,
uri: Option<&String>,
text: &str,
diff --git a/src/format.rs b/src/format.rs
index 279b4ab..ab9e4fa 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -1,7 +1,6 @@
-use std::{collections::HashMap, error::Error};
+use std::error::Error;
-use crate::value::Value;
-use crate::map::Map;
+use crate::{map::Map, value::Value};
/// Describes a format of configuration source data
///
diff --git a/src/lib.rs b/src/lib.rs
index e5ee901..48b5cd5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -56,8 +56,8 @@ mod de;
mod env;
mod error;
mod file;
-mod map;
mod format;
+mod map;
mod path;
mod ser;
mod source;
@@ -68,9 +68,9 @@ pub use crate::builder::ConfigBuilder;
pub use crate::config::Config;
pub use crate::env::Environment;
pub use crate::error::ConfigError;
-pub use crate::map::Map;
pub use crate::file::{File, FileExtensions, FileFormat, FileSourceFile, FileSourceString};
pub use crate::format::Format;
+pub use crate::map::Map;
pub use crate::source::AsyncSource;
pub use crate::source::Source;
pub use crate::value::Value;