Skip to content

Commit

Permalink
Apply clippy lints and format
Browse files Browse the repository at this point in the history
  • Loading branch information
szarykott committed Oct 17, 2021
1 parent dc94a83 commit 01bea1c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
10 changes: 6 additions & 4 deletions examples/async_source/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions examples/custom_format/main.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/file/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ mod de;
mod env;
mod error;
mod file;
mod map;
mod format;
mod map;
mod path;
mod ser;
mod source;
Expand All @@ -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;
Expand Down

0 comments on commit 01bea1c

Please sign in to comment.