Skip to content

Commit b3e39dd

Browse files
committed
Remove Config::new()
Removes the ::new() constructor, because Config::default() does the same. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 parent 20d3772 commit b3e39dd

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ impl Default for ConfigKind {
3939
/// A prioritized configuration repository. It maintains a set of
4040
/// configuration sources, fetches values to populate those, and provides
4141
/// them according to the source's priority.
42-
#[derive(Default, Clone, Debug)]
42+
#[derive(Clone, Debug)]
4343
pub struct Config {
4444
kind: ConfigKind,
4545

4646
/// Root of the cached configuration.
4747
pub cache: Value,
4848
}
4949

50-
impl Config {
51-
pub fn new() -> Self {
52-
Self {
50+
impl Default for Config {
51+
fn default() -> Self {
52+
Config {
5353
kind: ConfigKind::default(),
54-
// Config root should be instantiated as an empty table
55-
// to avoid deserialization errors.
5654
cache: Value::new(None, Table::new()),
5755
}
5856
}
57+
}
5958

59+
impl Config {
6060
/// Merge in a configuration property source.
6161
pub fn merge<T>(&mut self, source: T) -> Result<&mut Config>
6262
where

tests/defaults.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Default for Settings {
2121

2222
#[test]
2323
fn set_defaults() {
24-
let c = Config::new();
24+
let c = Config::default();
2525
let s: Settings = c.try_into().expect("Deserialization failed");
2626

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

tests/empty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ struct Settings {
1515

1616
#[test]
1717
fn empty_deserializes() {
18-
let s: Settings = Config::new().try_into().expect("Deserialization failed");
18+
let s: Settings = Config::default()
19+
.try_into()
20+
.expect("Deserialization failed");
1921
assert_eq!(s.foo, 0);
2022
assert_eq!(s.bar, 0);
2123
}

tests/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ inner:
120120
test: ABC
121121
"#;
122122

123-
let mut cfg = Config::new();
123+
let mut cfg = Config::default();
124124
cfg.merge(File::from_str(CFG, FileFormat::Yaml)).unwrap();
125125
let e = cfg.try_into::<Outer>().unwrap_err();
126126
if let ConfigError::Type {

0 commit comments

Comments
 (0)