Skip to content

Commit 834480a

Browse files
committed
Remove try_defaults_from and set_defaults (for now) as '#[serde(default)]' works thanks to #106
1 parent c03fd36 commit 834480a

File tree

2 files changed

+2
-31
lines changed

2 files changed

+2
-31
lines changed

src/config.rs

-28
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,6 @@ impl Config {
134134
self.refresh()
135135
}
136136

137-
/// Set the configuration defaults by serializing them from given value.
138-
pub fn set_defaults<T>(&mut self, value: &T) -> Result<&mut Config>
139-
where
140-
T: Serialize,
141-
{
142-
match self.kind {
143-
ConfigKind::Mutable {
144-
ref mut defaults, ..
145-
} => {
146-
for (key, val) in Self::try_from(&value)?.collect()? {
147-
defaults.insert(key.parse()?, val);
148-
}
149-
}
150-
151-
ConfigKind::Frozen => return Err(ConfigError::Frozen),
152-
}
153-
154-
self.refresh()
155-
}
156-
157137
pub fn set<T>(&mut self, key: &str, value: T) -> Result<&mut Config>
158138
where
159139
T: Into<Value>,
@@ -224,14 +204,6 @@ impl Config {
224204
Ok(serializer.output)
225205
}
226206

227-
/// Attempt to serialize the entire configuration from the given type
228-
/// as default values.
229-
pub fn try_defaults_from<T: Serialize>(from: &T) -> Result<Self> {
230-
let mut c = Self::new();
231-
c.set_defaults(from)?;
232-
Ok(c)
233-
}
234-
235207
#[deprecated(since = "0.7.0", note = "please use 'try_into' instead")]
236208
pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
237209
self.try_into()

tests/defaults.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate serde_derive;
66
use config::*;
77

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

2122
#[test]
2223
fn set_defaults() {
23-
let mut c = Config::new();
24-
c.set_defaults(&Settings::default())
25-
.expect("Setting defaults failed");
24+
let c = Config::new();
2625
let s: Settings = c.try_into().expect("Deserialization failed");
2726

2827
assert_eq!(s.db_host, "default");

0 commit comments

Comments
 (0)