Repository: mehcode/config-rs (rust)

Issue:
Does `Config::new()` returns the same as `Config::default()`?
Does `Config::new()` returns (effectively) the same as `Config::default()`? If not, better to document how are they different. If so, should `Config::new()` just delegate to `Config::default()` in the implementation?

Pull request:
Remove Config::new()
Closes #113 

Patch:
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<T>(&mut self, source: T) -> Result<&mut Config>
     where


Test patch:
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::<Outer>().unwrap_err();
     if let ConfigError::Type {