From b3e39dd1752fa929c9ddb66e4d6d0625632ac676 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 19 Mar 2021 10:17:33 +0100 Subject: Remove Config::new() Removes the ::new() constructor, because Config::default() does the same. Signed-off-by: Matthias Beyer --- src/config.rs | 12 ++++++------ tests/defaults.rs | 2 +- tests/empty.rs | 4 +++- tests/errors.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index cfd865a..94658da 100644 --- a/src/config.rs +++ b/src/config.rs @@ -39,7 +39,7 @@ impl Default for ConfigKind { /// A prioritized configuration repository. It maintains a set of /// configuration sources, fetches values to populate those, and provides /// them according to the source's priority. -#[derive(Default, Clone, Debug)] +#[derive(Clone, Debug)] pub struct Config { kind: ConfigKind, @@ -47,16 +47,16 @@ pub struct Config { pub cache: Value, } -impl Config { - pub fn new() -> Self { - Self { +impl Default for Config { + fn default() -> Self { + Config { kind: ConfigKind::default(), - // Config root should be instantiated as an empty table - // to avoid deserialization errors. cache: Value::new(None, Table::new()), } } +} +impl Config { /// Merge in a configuration property source. pub fn merge(&mut self, source: T) -> Result<&mut Config> where diff --git a/tests/defaults.rs b/tests/defaults.rs index 8d863ae..5cb86f3 100644 --- a/tests/defaults.rs +++ b/tests/defaults.rs @@ -21,7 +21,7 @@ impl Default for Settings { #[test] fn set_defaults() { - let c = Config::new(); + let c = Config::default(); let s: Settings = c.try_into().expect("Deserialization failed"); assert_eq!(s.db_host, "default"); diff --git a/tests/empty.rs b/tests/empty.rs index 1f56d38..a763a1b 100644 --- a/tests/empty.rs +++ b/tests/empty.rs @@ -15,7 +15,9 @@ struct Settings { #[test] fn empty_deserializes() { - let s: Settings = Config::new().try_into().expect("Deserialization failed"); + let s: Settings = Config::default() + .try_into() + .expect("Deserialization failed"); assert_eq!(s.foo, 0); assert_eq!(s.bar, 0); } diff --git a/tests/errors.rs b/tests/errors.rs index 47dd050..c16ac9a 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -120,7 +120,7 @@ inner: test: ABC "#; - let mut cfg = Config::new(); + let mut cfg = Config::default(); cfg.merge(File::from_str(CFG, FileFormat::Yaml)).unwrap(); let e = cfg.try_into::().unwrap_err(); if let ConfigError::Type { -- cgit v1.2.3