File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ use ser::ConfigSerializer;
10
10
use source:: Source ;
11
11
12
12
use path;
13
- use value:: { Value , ValueKind , ValueWithKey } ;
13
+ use value:: { Table , Value , ValueKind , ValueWithKey } ;
14
14
15
15
#[ derive( Clone , Debug ) ]
16
16
enum ConfigKind {
@@ -49,7 +49,12 @@ pub struct Config {
49
49
50
50
impl Config {
51
51
pub fn new ( ) -> Self {
52
- Config :: default ( )
52
+ Self {
53
+ kind : ConfigKind :: default ( ) ,
54
+ // Config root should be instantiated as an empty table
55
+ // to avoid deserialization errors.
56
+ cache : Value :: new ( None , Table :: new ( ) ) ,
57
+ }
53
58
}
54
59
55
60
/// Merge in a configuration property source.
Original file line number Diff line number Diff line change
1
+ extern crate config;
2
+
3
+ #[ macro_use]
4
+ extern crate serde_derive;
5
+
6
+ use config:: * ;
7
+
8
+ #[ derive( Debug , Serialize , Deserialize ) ]
9
+ struct Settings {
10
+ #[ serde( skip) ]
11
+ foo : isize ,
12
+ #[ serde( skip) ]
13
+ bar : u8 ,
14
+ }
15
+
16
+ #[ test]
17
+ fn empty_deserializes ( ) {
18
+ let s: Settings = Config :: new ( ) . try_into ( ) . expect ( "Deserialization failed" ) ;
19
+ assert_eq ! ( s. foo, 0 ) ;
20
+ assert_eq ! ( s. bar, 0 ) ;
21
+ }
You can’t perform that action at this time.
0 commit comments