File tree Expand file tree Collapse file tree 4 files changed +11
-9
lines changed Expand file tree Collapse file tree 4 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -39,24 +39,24 @@ impl Default for ConfigKind {
39
39
/// A prioritized configuration repository. It maintains a set of
40
40
/// configuration sources, fetches values to populate those, and provides
41
41
/// them according to the source's priority.
42
- #[ derive( Default , Clone , Debug ) ]
42
+ #[ derive( Clone , Debug ) ]
43
43
pub struct Config {
44
44
kind : ConfigKind ,
45
45
46
46
/// Root of the cached configuration.
47
47
pub cache : Value ,
48
48
}
49
49
50
- impl Config {
51
- pub fn new ( ) -> Self {
52
- Self {
50
+ impl Default for Config {
51
+ fn default ( ) -> Self {
52
+ Config {
53
53
kind : ConfigKind :: default ( ) ,
54
- // Config root should be instantiated as an empty table
55
- // to avoid deserialization errors.
56
54
cache : Value :: new ( None , Table :: new ( ) ) ,
57
55
}
58
56
}
57
+ }
59
58
59
+ impl Config {
60
60
/// Merge in a configuration property source.
61
61
pub fn merge < T > ( & mut self , source : T ) -> Result < & mut Config >
62
62
where
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ impl Default for Settings {
21
21
22
22
#[ test]
23
23
fn set_defaults ( ) {
24
- let c = Config :: new ( ) ;
24
+ let c = Config :: default ( ) ;
25
25
let s: Settings = c. try_into ( ) . expect ( "Deserialization failed" ) ;
26
26
27
27
assert_eq ! ( s. db_host, "default" ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ struct Settings {
15
15
16
16
#[ test]
17
17
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" ) ;
19
21
assert_eq ! ( s. foo, 0 ) ;
20
22
assert_eq ! ( s. bar, 0 ) ;
21
23
}
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ inner:
120
120
test: ABC
121
121
"# ;
122
122
123
- let mut cfg = Config :: new ( ) ;
123
+ let mut cfg = Config :: default ( ) ;
124
124
cfg. merge ( File :: from_str ( CFG , FileFormat :: Yaml ) ) . unwrap ( ) ;
125
125
let e = cfg. try_into :: < Outer > ( ) . unwrap_err ( ) ;
126
126
if let ConfigError :: Type {
You can’t perform that action at this time.
0 commit comments