Repository: rust-cli/config-rs (language: rust)

Issue:
Remove deprecated functions



Discussion / hints:

Fix patch:
diff --git a/examples/global/main.rs b/examples/global/main.rs
deleted file mode 100644
index f84a2095..00000000
--- a/examples/global/main.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-#![allow(deprecated)]
-use std::error::Error;
-use std::sync::OnceLock;
-use std::sync::RwLock;
-
-use config::Config;
-
-fn settings() -> &'static RwLock<Config> {
-    static CONFIG: OnceLock<RwLock<Config>> = OnceLock::new();
-    CONFIG.get_or_init(|| RwLock::new(Config::default()))
-}
-
-fn try_main() -> Result<(), Box<dyn Error>> {
-    // Set property
-    settings().write()?.set("property", 42)?;
-
-    // Get property
-    println!("property: {}", settings().read()?.get::<i32>("property")?);
-
-    Ok(())
-}
-
-fn main() {
-    try_main().unwrap();
-}
diff --git a/examples/watch/main.rs b/examples/watch/main.rs
index 7cdd822b..69200a10 100644
--- a/examples/watch/main.rs
+++ b/examples/watch/main.rs
@@ -1,4 +1,3 @@
-#![allow(deprecated)]
 use std::collections::HashMap;
 use std::path::Path;
 use std::sync::mpsc::channel;
@@ -12,15 +11,23 @@ use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher};
 fn settings() -> &'static RwLock<Config> {
     static CONFIG: OnceLock<RwLock<Config>> = OnceLock::new();
     CONFIG.get_or_init(|| {
-        let mut settings = Config::default();
-        settings
-            .merge(File::with_name("examples/watch/Settings.toml"))
-            .unwrap();
+        let settings = load();
 
         RwLock::new(settings)
     })
 }
 
+fn refresh() {
+    *settings().write().unwrap() = load();
+}
+
+fn load() -> Config {
+    Config::builder()
+        .add_source(File::with_name("examples/watch/Settings.toml"))
+        .build()
+        .unwrap()
+}
+
 fn show() {
     println!(
         " * Settings :: \n\x1b[31m{:?}\x1b[0m",
@@ -63,7 +70,7 @@ fn watch() -> ! {
                 ..
             })) => {
                 println!(" * Settings.toml written; refreshing configuration ...");
-                settings().write().unwrap().refresh().unwrap();
+                refresh();
                 show();
             }
 
diff --git a/src/builder.rs b/src/builder.rs
index 465f3ae9..6c6ab559 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -109,21 +109,6 @@ pub struct DefaultState {
     sources: Vec<Box<dyn Source + Send + Sync>>,
 }
 
-// Dummy useless struct
-//
-// This struct exists only to avoid the semver break
-// which would be implied by removing it.
-//
-// This struct cannot be used for anything useful.
-// (Nor can it be extended without a semver break, either.)
-//
-// In a future release, we should have
-//    type AsyncConfigBuilder = ConfigBuilder<AsyncState>;
-#[deprecated = "AsyncConfigBuilder is useless.  Use ConfigBuilder<AsyncState>"]
-#[doc(hidden)]
-#[derive(Debug, Clone, Default)]
-pub struct AsyncConfigBuilder {}
-
 /// Represents data specific to builder in asynchronous state, with support for async.
 #[derive(Debug, Default, Clone)]
 pub struct AsyncState {
diff --git a/src/config.rs b/src/config.rs
index e9818d7a..64d6b7f1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -48,40 +48,12 @@ impl Config {
         ConfigBuilder::<DefaultState>::default()
     }
 
-    /// Merge in a configuration property source.
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn merge<T>(&mut self, source: T) -> Result<&mut Self>
-    where
-        T: 'static,
-        T: Source + Send + Sync,
-    {
-        self.sources.push(Box::new(source));
-
-        #[allow(deprecated)]
-        self.refresh()
-    }
-
-    /// Merge in a configuration property source.
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn with_merged<T>(mut self, source: T) -> Result<Self>
-    where
-        T: 'static,
-        T: Source + Send + Sync,
-    {
-        self.sources.push(Box::new(source));
-
-        #[allow(deprecated)]
-        self.refresh()?;
-        Ok(self)
-    }
-
     /// Refresh the configuration cache with fresh
     /// data from added sources.
     ///
     /// Configuration is automatically refreshed after a mutation
     /// operation (`set`, `merge`, `set_default`, etc.).
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn refresh(&mut self) -> Result<&mut Self> {
+    fn refresh(&mut self) -> Result<&mut Self> {
         self.cache = {
             let mut cache: Value = Map::<String, Value>::new().into();
 
@@ -104,18 +76,6 @@ impl Config {
         Ok(self)
     }
 
-    /// Set a default `value` at `key`
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn set_default<T>(&mut self, key: &str, value: T) -> Result<&mut Self>
-    where
-        T: Into<Value>,
-    {
-        self.defaults.insert(key.parse()?, value.into());
-
-        #[allow(deprecated)]
-        self.refresh()
-    }
-
     /// Set an overwrite
     ///
     /// This function sets an overwrite value.
@@ -124,30 +84,15 @@ impl Config {
     /// # Warning
     ///
     /// Errors if config is frozen
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn set<T>(&mut self, key: &str, value: T) -> Result<&mut Self>
+    pub(crate) fn set<T>(&mut self, key: &str, value: T) -> Result<&mut Self>
     where
         T: Into<Value>,
     {
         self.overrides.insert(key.parse()?, value.into());
 
-        #[allow(deprecated)]
         self.refresh()
     }
 
-    #[deprecated(since = "0.12.0", note = "please use 'ConfigBuilder' instead")]
-    pub fn set_once(&mut self, key: &str, value: Value) -> Result<()> {
-        let expr: path::Expression = key.parse()?;
-
-        // Traverse the cache using the path to (possibly) retrieve a value
-        if let Some(ref mut val) = expr.get_mut(&mut self.cache) {
-            **val = value;
-        } else {
-            expr.set(&mut self.cache, value);
-        }
-        Ok(())
-    }
-
     fn get_value(&self, key: &str) -> Result<Value> {
         // Parse the key into a path expression
         let expr: path::Expression = key.parse()?;
@@ -206,11 +151,6 @@ impl Config {
         from.serialize(&mut serializer)?;
         Ok(serializer.output)
     }
-
-    #[deprecated(since = "0.7.0", note = "please use 'try_deserialize' instead")]
-    pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
-        self.try_deserialize()
-    }
 }
 
 impl Source for Config {
diff --git a/src/env.rs b/src/env.rs
index 2dad9235..564fdd69 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -91,11 +91,6 @@ pub struct Environment {
 }
 
 impl Environment {
-    #[deprecated(since = "0.12.0", note = "please use 'Environment::default' instead")]
-    pub fn new() -> Self {
-        Self::default()
-    }
-
     /// Optional prefix that will limit access to the environment to only keys that
     /// begin with the defined prefix.
     ///
diff --git a/src/lib.rs b/src/lib.rs
index 907d40ac..09cbafb7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,8 +39,6 @@ mod value;
 #[cfg(feature = "convert-case")]
 pub use convert_case::Case;
 
-#[allow(deprecated)]
-pub use crate::builder::AsyncConfigBuilder;
 pub use crate::builder::ConfigBuilder;
 pub use crate::config::Config;
 pub use crate::env::Environment;
diff --git a/src/path/mod.rs b/src/path/mod.rs
index 3908d933..52089de1 100644
--- a/src/path/mod.rs
+++ b/src/path/mod.rs
@@ -78,44 +78,6 @@ impl Expression {
         }
     }
 
-    pub(crate) fn get_mut<'a>(&self, root: &'a mut Value) -> Option<&'a mut Value> {
-        match *self {
-            Self::Identifier(ref id) => match root.kind {
-                ValueKind::Table(ref mut map) => map.get_mut(id),
-
-                _ => None,
-            },
-
-            Self::Child(ref expr, ref key) => match expr.get_mut(root) {
-                Some(value) => match value.kind {
-                    ValueKind::Table(ref mut map) => map.get_mut(key),
-
-                    _ => None,
-                },
-
-                _ => None,
-            },
-
-            Self::Subscript(ref expr, index) => match expr.get_mut(root) {
-                Some(value) => match value.kind {
-                    ValueKind::Array(ref mut array) => {
-                        let index = sindex_to_uindex(index, array.len());
-
-                        if index >= array.len() {
-                            None
-                        } else {
-                            Some(&mut array[index])
-                        }
-                    }
-
-                    _ => None,
-                },
-
-                _ => None,
-            },
-        }
-    }
-
     pub(crate) fn get_mut_forcibly<'a>(&self, root: &'a mut Value) -> Option<&'a mut Value> {
         match *self {
             Self::Identifier(ref id) => match root.kind {
diff --git a/src/ser.rs b/src/ser.rs
index b8fe8374..265683aa 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -45,7 +45,6 @@ impl ConfigSerializer {
         // That would be marginally more performant, but more fiddly.
         let key = self.make_full_key()?;
 
-        #[allow(deprecated)]
         self.output.set(&key, value.into())?;
         Ok(())
     }


Test patch: