From 1ef50eb8e7f51bc6d401b29d857235303a453423 Mon Sep 17 00:00:00 2001 From: stanisloe Date: Wed, 3 Apr 2024 17:23:48 +0100 Subject: [PATCH 1/2] remove deprecated dependency from app crate --- Cargo.toml | 2 +- crates/apps/src/lib/config/global.rs | 11 ++++++----- crates/apps/src/lib/config/mod.rs | 18 +++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 322238fb7e..d9658418b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ clap = "4.3.4" clru = {git = "https://github.com/marmeladema/clru-rs.git", rev = "71ca566"} color-eyre = "0.6.2" concat-idents = "1.1.2" -config = "0.11.0" +config = { git = "https://github.com/mehcode/config-rs.git", rev = "e3c1d0b452639478662a44f15ef6d5b6d969bf9b" } data-encoding = "2.3.2" derivation-path = "0.2.0" derivative = "2.2.0" diff --git a/crates/apps/src/lib/config/global.rs b/crates/apps/src/lib/config/global.rs index f6d917c770..62100e616c 100644 --- a/crates/apps/src/lib/config/global.rs +++ b/crates/apps/src/lib/config/global.rs @@ -43,13 +43,14 @@ impl GlobalConfig { pub fn read(base_dir: impl AsRef) -> Result { let file_path = Self::file_path(base_dir.as_ref()); let file_name = file_path.to_str().expect("Expected UTF-8 file path"); - let mut config = config::Config::new(); + let mut config = config::Config::default(); if file_path.exists() { - config - .merge(config::File::with_name(file_name)) - .map_err(Error::ReadError)?; + config = config::Config::builder() + .add_source(config::File::with_name(file_name)) + .build() + .map_err(Error::ReadError)?; } - config.try_into().map_err(Error::DeserializationError) + config.try_deserialize().map_err(|e: config::ConfigError| Error::DeserializationError(e)) } /// Write configuration to a file. diff --git a/crates/apps/src/lib/config/mod.rs b/crates/apps/src/lib/config/mod.rs index 782ffee77d..0b1922c380 100644 --- a/crates/apps/src/lib/config/mod.rs +++ b/crates/apps/src/lib/config/mod.rs @@ -273,17 +273,13 @@ impl Config { mode, )) .map_err(Error::ReadError)?; - let mut config = config::Config::new(); - config - .merge(defaults) - .and_then(|c| c.merge(config::File::with_name(file_name))) - .and_then(|c| { - c.merge( - config::Environment::with_prefix("NAMADA").separator("__"), - ) - }) - .map_err(Error::ReadError)?; - config.try_into().map_err(Error::DeserializationError) + let builder = config::Config::builder() + .add_source(defaults) + .add_source(config::File::with_name(file_name)) + .add_source(config::Environment::with_prefix("NAMADA").separator("__")); + + let config = builder.build().map_err(Error::ReadError)?; + config.try_deserialize().map_err(Error::DeserializationError) } /// Generate configuration and write it to a file. From ad9703b4daebc2f1e590f980b7ee18194555897c Mon Sep 17 00:00:00 2001 From: stanisloe Date: Wed, 3 Apr 2024 18:03:45 +0100 Subject: [PATCH 2/2] fix clippy-fmt check --- crates/apps/src/lib/config/global.rs | 10 ++++++---- crates/apps/src/lib/config/mod.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/apps/src/lib/config/global.rs b/crates/apps/src/lib/config/global.rs index 62100e616c..ef1d5ecf5d 100644 --- a/crates/apps/src/lib/config/global.rs +++ b/crates/apps/src/lib/config/global.rs @@ -46,11 +46,13 @@ impl GlobalConfig { let mut config = config::Config::default(); if file_path.exists() { config = config::Config::builder() - .add_source(config::File::with_name(file_name)) - .build() - .map_err(Error::ReadError)?; + .add_source(config::File::with_name(file_name)) + .build() + .map_err(Error::ReadError)?; } - config.try_deserialize().map_err(|e: config::ConfigError| Error::DeserializationError(e)) + config + .try_deserialize() + .map_err(|e: config::ConfigError| Error::DeserializationError(e)) } /// Write configuration to a file. diff --git a/crates/apps/src/lib/config/mod.rs b/crates/apps/src/lib/config/mod.rs index 0b1922c380..c4292a0570 100644 --- a/crates/apps/src/lib/config/mod.rs +++ b/crates/apps/src/lib/config/mod.rs @@ -276,10 +276,14 @@ impl Config { let builder = config::Config::builder() .add_source(defaults) .add_source(config::File::with_name(file_name)) - .add_source(config::Environment::with_prefix("NAMADA").separator("__")); + .add_source( + config::Environment::with_prefix("NAMADA").separator("__"), + ); let config = builder.build().map_err(Error::ReadError)?; - config.try_deserialize().map_err(Error::DeserializationError) + config + .try_deserialize() + .map_err(Error::DeserializationError) } /// Generate configuration and write it to a file.