@@ -22,7 +22,6 @@ pub struct Ini {
22
22
case_sensitive : bool ,
23
23
}
24
24
25
-
26
25
///The `IniDefault` struct serves as a template to create other `Ini` objects from. It can be used to store and load
27
26
///default properties from different `Ini` objects.
28
27
///## Example
@@ -31,7 +30,7 @@ pub struct Ini {
31
30
///
32
31
///let mut config = Ini::new();
33
32
///let default = config.defaults();
34
- ///let mut config2 = Ini::new_from_defaults(default);
33
+ ///let mut config2 = Ini::new_from_defaults(default); // default gets consumed
35
34
///```
36
35
#[ derive( Debug , Clone , Eq , PartialEq , Default ) ]
37
36
pub struct IniDefault {
@@ -92,9 +91,11 @@ impl Ini {
92
91
/// delimiters: vec!['='],
93
92
/// case_sensitive: true,
94
93
///};
95
- ///let mut config = Ini::new_from_defaults(default);
94
+ ///let mut config = Ini::new_from_defaults(default.clone() );
96
95
///// Now, load as usual with new defaults:
97
96
///let map = config.load("tests/test.ini").unwrap();
97
+ ///assert_eq!(config.defaults(), default);
98
+ ///assert_eq!(config.defaults(), config.defaults());
98
99
///
99
100
///```
100
101
pub fn new_from_defaults ( defaults : IniDefault ) -> Ini {
@@ -115,12 +116,12 @@ impl Ini {
115
116
///let mut config = Ini::new();
116
117
///let default = config.defaults();
117
118
///```
118
- ///Returns an `IniDefault` object.
119
- pub fn defaults ( self ) -> IniDefault {
119
+ ///Returns an `IniDefault` object. Keep in mind that it will get borrowed since it has non-`Copy` types.
120
+ pub fn defaults ( & self ) -> IniDefault {
120
121
IniDefault {
121
- default_section : self . default_section ,
122
- comment_symbols : self . comment_symbols ,
123
- delimiters : self . delimiters ,
122
+ default_section : self . default_section . to_owned ( ) ,
123
+ comment_symbols : self . comment_symbols . to_owned ( ) ,
124
+ delimiters : self . delimiters . to_owned ( ) ,
124
125
case_sensitive : self . case_sensitive ,
125
126
}
126
127
}
@@ -139,7 +140,8 @@ impl Ini {
139
140
/// delimiters: vec!['=', ':'],
140
141
/// case_sensitive: true,
141
142
///}; // This is equivalent to ini_cs() defaults
142
- ///config.load_defaults(default);
143
+ ///config.load_defaults(default.clone());
144
+ ///assert_eq!(config.defaults(), default);
143
145
///```
144
146
///Returns nothing.
145
147
pub fn load_defaults ( & mut self , defaults : IniDefault ) {
0 commit comments