@@ -22,6 +22,17 @@ pub struct Ini {
22
22
case_sensitive : bool ,
23
23
}
24
24
25
+
26
+ ///The `IniDefault` struct serves as a template to create other `Ini` objects from. It can be used to store and load
27
+ ///default properties from different `Ini` objects.
28
+ ///## Example
29
+ ///```rust
30
+ ///use configparser::ini::Ini;
31
+ ///
32
+ ///let mut config = Ini::new();
33
+ ///let default = config.defaults();
34
+ ///let mut config2 = Ini::new_from_defaults(default);
35
+ ///```
25
36
#[ derive( Debug , Clone , Eq , PartialEq , Default ) ]
26
37
pub struct IniDefault {
27
38
pub default_section : std:: string:: String ,
@@ -69,6 +80,23 @@ impl Ini {
69
80
}
70
81
}
71
82
83
+ ///Creates a new `Ini` with the given defaults from an existing `IniDefault` object.
84
+ ///## Example
85
+ ///```rust
86
+ ///use configparser::ini::Ini;
87
+ ///use configparser::ini::IniDefault;
88
+ ///
89
+ ///let default = IniDefault {
90
+ /// default_section: "default".to_owned(),
91
+ /// comment_symbols: vec![';'],
92
+ /// delimiters: vec!['='],
93
+ /// case_sensitive: true,
94
+ ///};
95
+ ///let mut config = Ini::new_from_defaults(default);
96
+ ///// Now, load as usual with new defaults:
97
+ ///let map = config.load("tests/test.ini").unwrap();
98
+ ///
99
+ ///```
72
100
pub fn new_from_defaults ( defaults : IniDefault ) -> Ini {
73
101
Ini {
74
102
map : HashMap :: new ( ) ,
@@ -102,14 +130,15 @@ impl Ini {
102
130
///## Example
103
131
///```rust
104
132
///use configparser::ini::Ini;
133
+ ///use configparser::ini::IniDefault;
105
134
///
106
135
///let mut config = Ini::new();
107
136
///let default = IniDefault {
108
137
/// default_section: "default".to_owned(),
109
138
/// comment_symbols: vec![';', '#'],
110
139
/// delimiters: vec!['=', ':'],
111
140
/// case_sensitive: true,
112
- ///} // This is equivalent to ini_cs() defaults
141
+ ///}; // This is equivalent to ini_cs() defaults
113
142
///config.load_defaults(default);
114
143
///```
115
144
///Returns nothing.
0 commit comments