Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
resolver = "2"
resolver = "3"

[workspace.package]
repository = "https://github.com/rust-cli/config-rs"
license = "MIT OR Apache-2.0"
edition = "2018"
rust-version = "1.76.0" # MSRV
edition = "2024"
rust-version = "1.85.0" # MSRV
include = [
"build.rs",
"src/**/*",
Expand Down
4 changes: 2 additions & 2 deletions examples/async_source/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::{error::Error, fmt::Debug};

use async_trait::async_trait;
use config::{
builder::AsyncState, AsyncSource, ConfigBuilder, ConfigError, FileFormat, Format, Map,
AsyncSource, ConfigBuilder, ConfigError, FileFormat, Format, Map, builder::AsyncState,
};
use futures::{select, FutureExt};
use futures::{FutureExt, select};
use warp::Filter;

// Example below presents sample configuration server and client.
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_file_format/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Format for PemFile {
return Err(Box::new(Error::new(
ErrorKind::InvalidData,
"PEM file did not contain a Private or Public key",
)))
)));
}
};

Expand Down
5 changes: 2 additions & 3 deletions examples/env-list/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use config::Config;

#[derive(Debug, Default, serde::Deserialize, PartialEq, Eq)]
struct AppConfig {
list: Vec<String>,
}

fn main() {
std::env::set_var("APP_LIST", "Hello World");
// e.g. set `APP_LIST="Hello World"

let config = Config::builder()
.add_source(
Expand All @@ -20,6 +21,4 @@ fn main() {
let app: AppConfig = config.try_deserialize().unwrap();

assert_eq!(app.list, vec![String::from("Hello"), String::from("World")]);

std::env::remove_var("APP_LIST");
}
2 changes: 1 addition & 1 deletion examples/watch/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;
use std::path::Path;
use std::sync::mpsc::channel;
use std::sync::OnceLock;
use std::sync::RwLock;
use std::sync::mpsc::channel;
use std::time::Duration;

use config::{Config, File};
Expand Down
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'de> de::MapAccess<'de> for MapAccess {
where
K: de::DeserializeSeed<'de>,
{
if let Some((ref key_s, _)) = self.elements.front() {
if let Some((key_s, _)) = self.elements.front() {
let key_de = Value::new(None, key_s as &str);
let key = de::DeserializeSeed::deserialize(seed, key_de)?;

Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::ffi::OsString;
#[cfg(feature = "convert-case")]
use convert_case::{Case, Casing};

use crate::ConfigError;
use crate::error::Result;
use crate::map::Map;
use crate::source::Source;
use crate::value::{Value, ValueKind};
use crate::ConfigError;

/// An environment source collects a dictionary of environment variables values into a hierarchical
/// config Value type. We have to be aware how the config tree is created from the environment
Expand Down
4 changes: 2 additions & 2 deletions src/file/format/corn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::value::{Value, ValueKind};
use crate::{format, Map};
use crate::value::{Value, ValueKind};
use crate::{Map, format};
use std::error::Error;

pub(crate) fn parse(
Expand Down
2 changes: 1 addition & 1 deletion src/file/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;

use crate::map::Map;
use crate::{file::FileStoredFormat, value::Value, Format};
use crate::{Format, file::FileStoredFormat, value::Value};

#[cfg(feature = "toml")]
mod toml;
Expand Down
2 changes: 1 addition & 1 deletion src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::fmt::Debug;
use std::path::{Path, PathBuf};

use self::source::FileSource;
use crate::Format;
use crate::error::{ConfigError, Result};
use crate::map::Map;
use crate::source::Source;
use crate::value::Value;
use crate::Format;

pub use self::format::FileFormat;
pub use self::source::file::FileSourceFile;
Expand Down
2 changes: 1 addition & 1 deletion src/file/source/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs;
use std::io;
use std::path::PathBuf;

use crate::file::{source::FileSourceResult, FileFormat, FileSource, FileStoredFormat, Format};
use crate::file::{FileFormat, FileSource, FileStoredFormat, Format, source::FileSourceResult};

/// Describes a file sourced from a file
#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/file/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) mod string;
use std::error::Error;
use std::fmt::Debug;

use crate::{file::FileStoredFormat, Format};
use crate::{Format, file::FileStoredFormat};

/// Describes where the [`File`][super::File] is sourced
pub trait FileSource<T>: Debug + Clone
Expand Down
2 changes: 1 addition & 1 deletion src/file/source/string.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::error::Error;

use crate::{
Format,
file::source::FileSourceResult,
file::{FileSource, FileStoredFormat},
Format,
};

/// Describes a file sourced from a string
Expand Down
4 changes: 2 additions & 2 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::fmt::Write as _;

use serde_core::ser;

use crate::Config;
use crate::error::{ConfigError, Result};
use crate::value::{Value, ValueKind};
use crate::Config;

#[derive(Default, Debug)]
pub(crate) struct ConfigSerializer {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ser::SerializeSeq for SeqSerializer<'_> {
_ => {
return Err(ConfigError::Message(
"config-rs internal error (ser._element but last not Seq!".to_owned(),
))
));
}
};
Ok(())
Expand Down
20 changes: 15 additions & 5 deletions tests/testsuite/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_root_not_table() {
"invalid type: boolean `false`, expected a map",
format!("{cause}")
),
_ => panic!("Wrong error: {:?}", e),
_ => panic!("Wrong error: {e:?}"),
}
}

Expand Down Expand Up @@ -304,7 +304,12 @@ fn test_value_deserialize_enum() {

let array_v: Value = vec![100, 100].into();
let array_d = array_v.try_deserialize::<Diode>();
assert_data_eq!(array_d.unwrap_err().to_string(), str!["value of enum Diode should be represented by either string or table with exactly one key"]);
assert_data_eq!(
array_d.unwrap_err().to_string(),
str![
"value of enum Diode should be represented by either string or table with exactly one key"
]
);

let confused_v: Value = [
("Brightness".to_owned(), 100.into()),
Expand All @@ -315,7 +320,12 @@ fn test_value_deserialize_enum() {
.collect::<Map<String, Value>>()
.into();
let confused_d = confused_v.try_deserialize::<Diode>();
assert_data_eq!(confused_d.unwrap_err().to_string(), str!["value of enum Diode should be represented by either string or table with exactly one key"]);
assert_data_eq!(
confused_d.unwrap_err().to_string(),
str![
"value of enum Diode should be represented by either string or table with exactly one key"
]
);
}

#[test]
Expand Down Expand Up @@ -359,7 +369,7 @@ fn test_deserialize_invalid_type() {
{
assert_eq!(path, "place.name");
} else {
panic!("Wrong error {:?}", e);
panic!("Wrong error {e:?}");
}
}

Expand Down Expand Up @@ -400,7 +410,7 @@ fn test_deserialize_invalid_type_file() {
{
assert_eq!(path, "place.name");
} else {
panic!("Wrong error {:?}", e);
panic!("Wrong error {e:?}");
}
}

Expand Down
20 changes: 16 additions & 4 deletions tests/testsuite/file_corn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ fn test_override_uppercase_value_for_struct() {
FOO: String,
}

std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -205,7 +208,10 @@ fn test_override_lowercase_value_for_struct() {
bar: String,
}

std::env::set_var("config_foo", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -253,7 +259,10 @@ fn test_override_uppercase_value_for_enums() {
Bar(String),
}

std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -283,7 +292,10 @@ fn test_override_lowercase_value_for_enums() {
Bar(String),
}

std::env::set_var("test_bar", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down
20 changes: 16 additions & 4 deletions tests/testsuite/file_ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ fn test_override_uppercase_value_for_struct() {
FOO: String,
}

std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -148,7 +151,10 @@ fn test_override_lowercase_value_for_struct() {
bar: String,
}

std::env::set_var("config_foo", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -186,7 +192,10 @@ fn test_override_uppercase_value_for_enums() {
Bar(String),
}

std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -214,7 +223,10 @@ fn test_override_lowercase_value_for_enums() {
Bar(String),
}

std::env::set_var("test_bar", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down
20 changes: 16 additions & 4 deletions tests/testsuite/file_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ fn test_override_uppercase_value_for_struct() {
FOO: String,
}

std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -199,7 +202,10 @@ fn test_override_lowercase_value_for_struct() {
bar: String,
}

std::env::set_var("config_foo", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -247,7 +253,10 @@ fn test_override_uppercase_value_for_enums() {
Bar(String),
}

std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
// SAFETY: pure rust
unsafe {
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down Expand Up @@ -277,7 +286,10 @@ fn test_override_lowercase_value_for_enums() {
Bar(String),
}

std::env::set_var("test_bar", "I have been overridden_with_lower_case");
// SAFETY: pure rust
unsafe {
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
}

let cfg = Config::builder()
.add_source(File::from_str(
Expand Down
Loading
Loading