Skip to content

Commit

Permalink
Merge pull request #614 from epage/deprecated
Browse files Browse the repository at this point in the history
fix!: Remove deprecated APIs
  • Loading branch information
epage authored Dec 17, 2024
2 parents c9f32b0 + 5b3087f commit 35ba3bd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 154 deletions.
25 changes: 0 additions & 25 deletions examples/global/main.rs

This file was deleted.

19 changes: 13 additions & 6 deletions examples/watch/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(deprecated)]
use std::collections::HashMap;
use std::path::Path;
use std::sync::mpsc::channel;
Expand All @@ -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",
Expand Down Expand Up @@ -63,7 +70,7 @@ fn watch() -> ! {
..
})) => {
println!(" * Settings.toml written; refreshing configuration ...");
settings().write().unwrap().refresh().unwrap();
refresh();
show();
}

Expand Down
15 changes: 0 additions & 15 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
64 changes: 2 additions & 62 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.
Expand All @@ -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()?;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 35ba3bd

Please sign in to comment.