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 {
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 ) ]
4343pub 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
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ impl Default for Settings {
2121
2222#[ test]
2323fn 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" ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ struct Settings {
1515
1616#[ test]
1717fn 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}
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments