Skip to content

Commit 85a4d04

Browse files
committed
🆕 Finish adding new APIs
1 parent b81ba42 commit 85a4d04

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/ini.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ pub struct Ini {
2222
case_sensitive: bool,
2323
}
2424

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+
///```
2536
#[derive(Debug, Clone, Eq, PartialEq, Default)]
2637
pub struct IniDefault {
2738
pub default_section: std::string::String,
@@ -69,6 +80,23 @@ impl Ini {
6980
}
7081
}
7182

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+
///```
72100
pub fn new_from_defaults(defaults: IniDefault) -> Ini {
73101
Ini {
74102
map: HashMap::new(),
@@ -102,14 +130,15 @@ impl Ini {
102130
///## Example
103131
///```rust
104132
///use configparser::ini::Ini;
133+
///use configparser::ini::IniDefault;
105134
///
106135
///let mut config = Ini::new();
107136
///let default = IniDefault {
108137
/// default_section: "default".to_owned(),
109138
/// comment_symbols: vec![';', '#'],
110139
/// delimiters: vec!['=', ':'],
111140
/// case_sensitive: true,
112-
///} // This is equivalent to ini_cs() defaults
141+
///}; // This is equivalent to ini_cs() defaults
113142
///config.load_defaults(default);
114143
///```
115144
///Returns nothing.

0 commit comments

Comments
 (0)