summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-03-19 10:17:33 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-26 17:01:26 +0100
commitb3e39dd1752fa929c9ddb66e4d6d0625632ac676 (patch)
tree64107176933afeee92823712ac4497cfe2adbf69
parent20d37720b0342e68cd3c8c2c2a437b8634ec3642 (diff)
Remove Config::new()
Removes the ::new() constructor, because Config::default() does the same. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/config.rs12
-rw-r--r--tests/defaults.rs2
-rw-r--r--tests/empty.rs4
-rw-r--r--tests/errors.rs2
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<T>(&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::<Outer>().unwrap_err();
if let ConfigError::Type {