Skip to content

Commit

Permalink
Remove try_defaults_from and set_defaults (for now) as '#[serde(defau…
Browse files Browse the repository at this point in the history
…lt)]' works thanks to #106
  • Loading branch information
mehcode committed May 9, 2019
1 parent c03fd36 commit 834480a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
28 changes: 0 additions & 28 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,6 @@ impl Config {
self.refresh()
}

/// Set the configuration defaults by serializing them from given value.
pub fn set_defaults<T>(&mut self, value: &T) -> Result<&mut Config>
where
T: Serialize,
{
match self.kind {
ConfigKind::Mutable {
ref mut defaults, ..
} => {
for (key, val) in Self::try_from(&value)?.collect()? {
defaults.insert(key.parse()?, val);
}
}

ConfigKind::Frozen => return Err(ConfigError::Frozen),
}

self.refresh()
}

pub fn set<T>(&mut self, key: &str, value: T) -> Result<&mut Config>
where
T: Into<Value>,
Expand Down Expand Up @@ -224,14 +204,6 @@ impl Config {
Ok(serializer.output)
}

/// Attempt to serialize the entire configuration from the given type
/// as default values.
pub fn try_defaults_from<T: Serialize>(from: &T) -> Result<Self> {
let mut c = Self::new();
c.set_defaults(from)?;
Ok(c)
}

#[deprecated(since = "0.7.0", note = "please use 'try_into' instead")]
pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
self.try_into()
Expand Down
5 changes: 2 additions & 3 deletions tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate serde_derive;
use config::*;

#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
pub db_host: String,
}
Expand All @@ -20,9 +21,7 @@ impl Default for Settings {

#[test]
fn set_defaults() {
let mut c = Config::new();
c.set_defaults(&Settings::default())
.expect("Setting defaults failed");
let c = Config::new();
let s: Settings = c.try_into().expect("Deserialization failed");

assert_eq!(s.db_host, "default");
Expand Down

0 comments on commit 834480a

Please sign in to comment.