summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2019-05-09 09:58:48 -0700
committerRyan Leckey <ryan@launchbadge.com>2019-05-09 09:58:48 -0700
commit834480a46c9c7b3b4b0e467b592ecc209e15b84c (patch)
tree129fd4bb4fbfbb6e14b4c586c0cf069dcac53184
parentc03fd36f4929bcb0a0bfa8ff601cb35ffb95106e (diff)
Remove try_defaults_from and set_defaults (for now) as '#[serde(default)]' works thanks to #106
-rw-r--r--src/config.rs28
-rw-r--r--tests/defaults.rs5
2 files changed, 2 insertions, 31 deletions
diff --git a/src/config.rs b/src/config.rs
index fa43e2a..2ce73f1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -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>,
@@ -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()
diff --git a/tests/defaults.rs b/tests/defaults.rs
index b00da29..8d863ae 100644
--- a/tests/defaults.rs
+++ b/tests/defaults.rs
@@ -6,6 +6,7 @@ extern crate serde_derive;
use config::*;
#[derive(Debug, Serialize, Deserialize)]
+#[serde(default)]
pub struct Settings {
pub db_host: String,
}
@@ -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");