File tree 2 files changed +2
-31
lines changed
2 files changed +2
-31
lines changed Original file line number Diff line number Diff line change @@ -134,26 +134,6 @@ impl Config {
134
134
self . refresh ( )
135
135
}
136
136
137
- /// Set the configuration defaults by serializing them from given value.
138
- pub fn set_defaults < T > ( & mut self , value : & T ) -> Result < & mut Config >
139
- where
140
- T : Serialize ,
141
- {
142
- match self . kind {
143
- ConfigKind :: Mutable {
144
- ref mut defaults, ..
145
- } => {
146
- for ( key, val) in Self :: try_from ( & value) ?. collect ( ) ? {
147
- defaults. insert ( key. parse ( ) ?, val) ;
148
- }
149
- }
150
-
151
- ConfigKind :: Frozen => return Err ( ConfigError :: Frozen ) ,
152
- }
153
-
154
- self . refresh ( )
155
- }
156
-
157
137
pub fn set < T > ( & mut self , key : & str , value : T ) -> Result < & mut Config >
158
138
where
159
139
T : Into < Value > ,
@@ -224,14 +204,6 @@ impl Config {
224
204
Ok ( serializer. output )
225
205
}
226
206
227
- /// Attempt to serialize the entire configuration from the given type
228
- /// as default values.
229
- pub fn try_defaults_from < T : Serialize > ( from : & T ) -> Result < Self > {
230
- let mut c = Self :: new ( ) ;
231
- c. set_defaults ( from) ?;
232
- Ok ( c)
233
- }
234
-
235
207
#[ deprecated( since = "0.7.0" , note = "please use 'try_into' instead" ) ]
236
208
pub fn deserialize < ' de , T : Deserialize < ' de > > ( self ) -> Result < T > {
237
209
self . try_into ( )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ extern crate serde_derive;
6
6
use config:: * ;
7
7
8
8
#[ derive( Debug , Serialize , Deserialize ) ]
9
+ #[ serde( default ) ]
9
10
pub struct Settings {
10
11
pub db_host : String ,
11
12
}
@@ -20,9 +21,7 @@ impl Default for Settings {
20
21
21
22
#[ test]
22
23
fn set_defaults ( ) {
23
- let mut c = Config :: new ( ) ;
24
- c. set_defaults ( & Settings :: default ( ) )
25
- . expect ( "Setting defaults failed" ) ;
24
+ let c = Config :: new ( ) ;
26
25
let s: Settings = c. try_into ( ) . expect ( "Deserialization failed" ) ;
27
26
28
27
assert_eq ! ( s. db_host, "default" ) ;
You can’t perform that action at this time.
0 commit comments