Debian Codegraph @

src/ini.rs

raw symbols SCIP
1 //!The ini module provides all the things necessary to load and parse ini-syntax files. The most important of which is the `Ini` struct.
2 //!See the [implementation](https://docs.rs/configparser/*/configparser/ini/struct.Ini.html) documentation for more details.
3 #[cfg(feature = "indexmap")]
4 use indexmaprust-analyzer cargo indexmap 2.14.0 crate/::IndexMaprust-analyzer cargo indexmap 2.14.0 map/IndexMap# as Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#;
5 #[cfg(not(feature = "indexmap"))]
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap# as Maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
7
8 #[cfg(feature = "async-std")]
9 use async_stdrust-analyzer cargo async-std 1.13.2 crate/::{fsrust-analyzer cargo async-std 1.13.2 fs/ as async_fsrust-analyzer cargo async-std 1.13.2 fs/, pathrust-analyzer cargo async-std 1.13.2 path/::Pathrust-analyzer cargo async-std 1.13.2 path/path/Path# as AsyncPathrust-analyzer cargo async-std 1.13.2 path/path/Path#};
10
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
12 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#;
13 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
14 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/;
15 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
16
17 ///The `Ini` struct simply contains a nested hashmap of the loaded configuration, the default section header and comment symbols.
18 ///## Example
19 ///```rust
20 ///use configparser::ini::Ini;
21 ///
22 ///let mut config = Ini::new();
23 ///```
24 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
25 #[non_exhaustive]
26 pub struct Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
27 maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.: Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>,
28 default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
29 comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char>,
30 delimitersrust-analyzer cargo configparser 3.0.3 ini/Ini#delimiters.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char>,
31 boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<bool, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
32 case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive.: bool,
33 multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline.: bool,
34 }
35
36 ///The `IniDefault` struct serves as a template to create other `Ini` objects from. It can be used to store and load
37 ///default properties from different `Ini` objects.
38 ///## Example
39 ///```rust
40 ///use configparser::ini::Ini;
41 ///
42 ///let mut config = Ini::new();
43 ///let default = config.defaults();
44 ///let mut config2 = Ini::new_from_defaults(default); // default gets consumed
45 ///```
46 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
47 #[non_exhaustive]
48 pub struct IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault# {
49 ///Denotes the default section header name.
50 ///## Example
51 ///```rust
52 ///use configparser::ini::Ini;
53 ///
54 ///let mut config = Ini::new();
55 ///let default = config.defaults();
56 ///assert_eq!(default.default_section, "default");
57 ///```
58 pub default_sectionrust-analyzer cargo configparser 3.0.3 ini/IniDefault#default_section.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
59 ///Denotes the set comment symbols for the object.
60 ///## Example
61 ///```rust
62 ///use configparser::ini::Ini;
63 ///
64 ///let mut config = Ini::new();
65 ///let default = config.defaults();
66 ///assert_eq!(default.comment_symbols, vec![';', '#']);
67 ///```
68 pub comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/IniDefault#comment_symbols.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char>,
69 ///Denotes the set delimiters for the key-value pairs.
70 ///## Example
71 ///```rust
72 ///use configparser::ini::Ini;
73 ///
74 ///let mut config = Ini::new();
75 ///let default = config.defaults();
76 ///assert_eq!(default.delimiters, vec!['=', ':']);
77 ///```
78 pub delimitersrust-analyzer cargo configparser 3.0.3 ini/IniDefault#delimiters.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char>,
79 pub boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/IniDefault#boolean_values.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<bool, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
80 ///Denotes if the `Ini` object is case-sensitive.
81 ///## Example
82 ///```rust
83 ///use configparser::ini::Ini;
84 ///
85 ///let mut config = Ini::new();
86 ///let default = config.defaults();
87 ///assert_eq!(default.case_sensitive, false);
88 ///```
89 pub case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.: bool,
90 ///Denotes if the `Ini` object parses multiline strings.
91 ///## Example
92 ///```rust
93 ///use configparser::ini::Ini;
94 ///
95 ///let mut config = Ini::new();
96 ///let default = config.defaults();
97 ///assert_eq!(default.multiline, false);
98 ///```
99 pub multilinerust-analyzer cargo configparser 3.0.3 ini/IniDefault#multiline.: bool,
100 }
101
102 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault# {
103 fn defaultrust-analyzer cargo configparser 3.0.3 ini/impl#[IniDefault][Default]default().() -> Selfrust-analyzer cargo configparser 3.0.3 ini/impl#[IniDefault][Default] {
104 Selfrust-analyzer cargo configparser 3.0.3 ini/impl#[IniDefault][Default] {
105 default_sectionrust-analyzer cargo configparser 3.0.3 ini/IniDefault#default_section.: "default".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
106 comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/IniDefault#comment_symbols.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![';', '#'],
107 delimitersrust-analyzer cargo configparser 3.0.3 ini/IniDefault#delimiters.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!['=', ':'],
108 multilinerust-analyzer cargo configparser 3.0.3 ini/IniDefault#multiline.: false,
109 boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/IniDefault#boolean_values.: [
110 (
111 true,
112 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["true", "yes", "t", "y", "on", "1"]
113 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
114 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())
115 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
116 ),
117 (
118 false,
119 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["false", "no", "f", "n", "off", "0"]
120 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
121 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())
122 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
123 ),
124 ]
125 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
126 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
127 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
128 case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.: false,
129 }
130 }
131 }
132
133 #[cfg(windows)]
134 const LINE_ENDING: &str = "\r\n";
135 #[cfg(not(windows))]
136 const LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING.: &str = "\n";
137
138 impl Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
139 ///Creates a new `Map` of `Map<String, Map<String, Option<String>>>` type for the struct.
140 ///All values in the Map are stored in `String` type.
141 ///
142 ///By default, [`std::collections::HashMap`] is used for the Map object.
143 ///The `indexmap` feature can be used to use an [`indexmap::map::IndexMap`] instead, which
144 ///allows keeping the insertion order for sections and keys.
145 ///
146 ///## Example
147 ///```rust
148 ///use configparser::ini::Ini;
149 ///
150 ///let mut config = Ini::new();
151 ///```
152 ///Returns the struct and stores it in the calling variable.
153 pub fn newrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]new().() -> Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
154 Inirust-analyzer cargo configparser 3.0.3 ini/Ini#::new_from_defaultsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]new_from_defaults().(IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault#::defaultrust-analyzer cargo configparser 3.0.3 ini/impl#[IniDefault][Default]default().())
155 }
156
157 ///Creates a new **case-sensitive** `Map` of `Map<String, Map<String, Option<String>>>` type for the struct.
158 ///All values in the Map are stored in `String` type.
159 ///## Example
160 ///```rust
161 ///use configparser::ini::Ini;
162 ///
163 ///let mut config = Ini::new_cs();
164 ///```
165 ///Returns the struct and stores it in the calling variable.
166 pub fn new_csrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]new_cs().() -> Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
167 Inirust-analyzer cargo configparser 3.0.3 ini/Ini#::new_from_defaultsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]new_from_defaults().(IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault# {
168 case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.: true,
169 ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo configparser 3.0.3 ini/impl#[IniDefault][Default]default().()
170 })
171 }
172
173 ///Creates a new `Ini` with the given defaults from an existing `IniDefault` object.
174 ///## Example
175 ///```rust
176 ///use configparser::ini::Ini;
177 ///use configparser::ini::IniDefault;
178 ///
179 ///let mut default = IniDefault::default();
180 ///default.comment_symbols = vec![';'];
181 ///default.delimiters = vec!['='];
182 ///let mut config = Ini::new_from_defaults(default.clone());
183 ///// Now, load as usual with new defaults:
184 ///let map = config.load("tests/test.ini").unwrap();
185 ///assert_eq!(config.defaults(), default);
186 ///
187 ///```
188 pub fn new_from_defaultsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]new_from_defaults().(defaults: IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault#) -> Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
189 Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
190 maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.: Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().(),
191 default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section.: defaults.default_sectionrust-analyzer cargo configparser 3.0.3 ini/IniDefault#default_section.,
192 comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols.: defaults.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/IniDefault#comment_symbols.,
193 delimitersrust-analyzer cargo configparser 3.0.3 ini/Ini#delimiters.: defaults.delimitersrust-analyzer cargo configparser 3.0.3 ini/IniDefault#delimiters.,
194 boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values.: defaults.boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/IniDefault#boolean_values.,
195 case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive.: defaults.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.,
196 multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline.: defaults.multilinerust-analyzer cargo configparser 3.0.3 ini/IniDefault#multiline.,
197 }
198 }
199
200 ///Fetches the defaults from the current `Ini` object and stores it as a `IniDefault` struct for usage elsewhere.
201 ///## Example
202 ///```rust
203 ///use configparser::ini::Ini;
204 ///
205 ///let mut config = Ini::new();
206 ///let default = config.defaults();
207 ///```
208 ///Returns an `IniDefault` object. Keep in mind that it will get borrowed since it has non-`Copy` types.
209 pub fn defaultsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]defaults().(&self) -> IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault# {
210 IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault# {
211 default_sectionrust-analyzer cargo configparser 3.0.3 ini/IniDefault#default_section.: self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
212 comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/IniDefault#comment_symbols.: self.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
213 delimitersrust-analyzer cargo configparser 3.0.3 ini/IniDefault#delimiters.: self.delimitersrust-analyzer cargo configparser 3.0.3 ini/Ini#delimiters..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
214 boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/IniDefault#boolean_values.: self.boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
215 case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.: self.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive.,
216 multilinerust-analyzer cargo configparser 3.0.3 ini/IniDefault#multiline.: self.multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline.,
217 }
218 }
219
220 ///Takes an `IniDefault` object and stores its properties in the calling `Ini` object. This happens in-place and
221 ///does not work retroactively, only future operations are affected.
222 ///## Example
223 ///```rust
224 ///use configparser::ini::Ini;
225 ///use configparser::ini::IniDefault;
226 ///
227 ///let mut config = Ini::new();
228 ///let mut default = IniDefault::default();
229 ///default.case_sensitive = true;
230 ///// This is equivalent to ini_cs() defaults
231 ///config.load_defaults(default.clone());
232 ///assert_eq!(config.defaults(), default);
233 ///```
234 ///Returns nothing.
235 pub fn load_defaultsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]load_defaults().(&mut self, defaults: IniDefaultrust-analyzer cargo configparser 3.0.3 ini/IniDefault#) {
236 self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section. = defaults.default_sectionrust-analyzer cargo configparser 3.0.3 ini/IniDefault#default_section.;
237 self.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols. = defaults.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/IniDefault#comment_symbols.;
238 self.delimitersrust-analyzer cargo configparser 3.0.3 ini/Ini#delimiters. = defaults.delimitersrust-analyzer cargo configparser 3.0.3 ini/IniDefault#delimiters.;
239 self.boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values. = defaults.boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/IniDefault#boolean_values.;
240 self.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive. = defaults.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/IniDefault#case_sensitive.;
241 }
242
243 ///Sets the default section header to the defined string (the default is `default`).
244 ///It must be set before `load()` or `read()` is called in order to take effect.
245 ///## Example
246 ///```rust
247 ///use configparser::ini::Ini;
248 ///
249 ///let mut config = Ini::new();
250 ///
251 ///config.set_default_section("topsecret");
252 ///let map = config.load("tests/test.ini").unwrap();
253 ///```
254 ///Returns nothing.
255 pub fn set_default_sectionrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]set_default_section().(&mut self, section: &str) {
256 self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section. = section.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
257 }
258
259 ///Sets the default comment symbols to the defined character slice (the defaults are `;` and `#`).
260 ///Keep in mind that this will remove the default symbols. It must be set before `load()` or `read()` is called in order to take effect.
261 ///## Example
262 ///```rust
263 ///use configparser::ini::Ini;
264 ///
265 ///let mut config = Ini::new();
266 ///config.set_comment_symbols(&['!', '#']);
267 ///let map = config.load("tests/test.ini").unwrap();
268 ///```
269 ///Returns nothing.
270 pub fn set_comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]set_comment_symbols().(&mut self, symlist: &[char]) {
271 self.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols. = symlist.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
272 }
273
274 ///Sets multiline string support.
275 ///It must be set before `load()` or `read()` is called in order to take effect.
276 ///## Example
277 ///```rust
278 ///use configparser::ini::Ini;
279 ///
280 ///let mut config = Ini::new();
281 ///config.set_multiline(true);
282 ///let map = config.load("tests/test.ini").unwrap();
283 ///```
284 ///Returns nothing.
285 pub fn set_multilinerust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]set_multiline().(&mut self, multiline: bool) {
286 self.multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline. = multiline;
287 }
288
289 ///Gets all the sections of the currently-stored `Map` in a vector.
290 ///## Example
291 ///```rust
292 ///use configparser::ini::Ini;
293 ///
294 ///let mut config = Ini::new();
295 ///config.load("tests/test.ini");
296 ///let sections = config.sections();
297 ///```
298 ///Returns `Vec<String>`.
299 pub fn sectionsrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]sections().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
300 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..keysrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]keys().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
301 }
302
303 ///Loads a file from a defined path, parses it and puts the hashmap into our struct.
304 ///At one time, it only stores one configuration, so each call to `load()` or `read()` will clear the existing `Map`, if present.
305 ///## Example
306 ///```rust
307 ///use configparser::ini::Ini;
308 ///
309 ///let mut config = Ini::new();
310 ///let map = config.load("tests/test.ini").unwrap(); // we can get a clone like this, or just store it
311 /////Then, we can use standard hashmap functions like:
312 ///let values = map.get("values").unwrap();
313 ///```
314 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
315 ///Use `get_mut_map()` if you want a mutable reference.
316 pub fn loadrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]load().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(
317 &mut self,
318 path: T,
319 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
320 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map. = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&path) {
321 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
322 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
323 "couldn't read {}: {}",
324 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
325 why
326 ))
327 }
328 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s,
329 }) {
330 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
331 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
332 "couldn't read {}: {}",
333 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
334 why
335 ))
336 }
337 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
338 };
339 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
340 }
341
342 ///Loads a file from a defined path, parses it and applies it to the existing hashmap in our struct.
343 ///While `load()` will clear the existing `Map`, `load_and_append()` applies the new values on top of
344 ///the existing hashmap, preserving previous values.
345 ///## Example
346 ///```rust
347 ///use configparser::ini::Ini;
348 ///
349 ///let mut config = Ini::new();
350 ///config.load("tests/test.ini").unwrap();
351 ///config.load_and_append("tests/sys_cfg.ini").ok(); // we don't have to worry if this doesn't succeed
352 ///config.load_and_append("tests/user_cfg.ini").ok(); // we don't have to worry if this doesn't succeed
353 ///let map = config.get_map().unwrap();
354 /////Then, we can use standard hashmap functions like:
355 ///let values = map.get("values").unwrap();
356 ///```
357 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
358 ///Use `get_mut_map()` if you want a mutable reference.
359 pub fn load_and_appendrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]load_and_append().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(
360 &mut self,
361 path: T,
362 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
363 let loaded = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&path) {
364 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
365 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
366 "couldn't read {}: {}",
367 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
368 why
369 ))
370 }
371 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s,
372 }) {
373 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
374 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
375 "couldn't read {}: {}",
376 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(),
377 why
378 ))
379 }
380 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
381 };
382
383 for (section, section_map) in loaded.iterrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]iter().() {
384 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.
385 .entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(section.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())
386 .or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().)
387 .extendrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][`Extend<(K, V)>`]extend().(section_map.clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().());
388 }
389
390 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
391 }
392
393 ///Reads an input string, parses it and puts the hashmap into our struct.
394 ///At one time, it only stores one configuration, so each call to `load()` or `read()` will clear the existing `Map`, if present.
395 ///## Example
396 ///```rust
397 ///use configparser::ini::Ini;
398 ///
399 ///let mut config = Ini::new();
400 ///let map = match config.read(String::from(
401 /// "[2000s]
402 /// 2020 = bad")) {
403 /// Err(why) => panic!("{}", why),
404 /// Ok(inner) => inner
405 ///};
406 ///let this_year = map["2000s"]["2020"].clone().unwrap();
407 ///assert_eq!(this_year, "bad"); // value accessible!
408 ///```
409 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
410 ///Use `get_mut_map()` if you want a mutable reference.
411 pub fn readrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]read().(
412 &mut self,
413 input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
414 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
415 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map. = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(input) {
416 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why),
417 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
418 };
419 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
420 }
421
422 ///Reads an input string, parses it and applies it to the existing hashmap in our struct.
423 ///While `read()` and `load()` will clear the existing `Map`, `read_and_append()` applies the new
424 ///values on top of the existing hashmap, preserving previous values.
425 ///## Example
426 ///```rust
427 ///use configparser::ini::Ini;
428 ///
429 ///let mut config = Ini::new();
430 ///if let Err(why) = config.read(String::from(
431 /// "[2000s]
432 /// 2020 = bad
433 /// 2023 = better")) {
434 /// panic!("{}", why);
435 ///};
436 ///if let Err(why) = config.read_and_append(String::from(
437 /// "[2000s]
438 /// 2020 = terrible")) {
439 /// panic!("{}", why);
440 ///};
441 ///let map = config.get_map().unwrap();
442 ///let few_years_ago = map["2000s"]["2020"].clone().unwrap();
443 ///let this_year = map["2000s"]["2023"].clone().unwrap();
444 ///assert_eq!(few_years_ago, "terrible"); // value updated!
445 ///assert_eq!(this_year, "better"); // keeps old values!
446 ///```
447 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
448 ///Use `get_mut_map()` if you want a mutable reference.
449 pub fn read_and_appendrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]read_and_append().(
450 &mut self,
451 input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
452 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
453 let loaded = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(input) {
454 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why),
455 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
456 };
457
458 for (section, section_map) in loaded.iterrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]iter().() {
459 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.
460 .entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(section.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())
461 .or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().)
462 .extendrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][`Extend<(K, V)>`]extend().(section_map.clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().());
463 }
464
465 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
466 }
467
468 ///Writes the current configuation to the specified path. If a file is not present, it is automatically created for you, if a file already
469 ///exists, it is truncated and the configuration is written to it.
470 ///## Example
471 ///```rust
472 ///use configparser::ini::Ini;
473 ///
474 ///fn main() -> std::io::Result<()> {
475 /// let mut config = Ini::new();
476 /// config.read(String::from(
477 /// "[2000s]
478 /// 2020 = bad"));
479 /// config.write("output.ini")
480 ///}
481 ///```
482 ///Returns a `std::io::Result<()>` type dependent on whether the write was successful or not.
483 pub fn writerust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]write().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(&self, path: T) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
484 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), self.unparserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]unparse().())
485 }
486
487 ///Returns a string with the current configuration formatted with valid ini-syntax. This is always safe since the configuration is validated during
488 ///parsing.
489 ///## Example
490 ///```rust
491 ///use configparser::ini::Ini;
492 ///
493 ///let mut config = Ini::new();
494 ///config.read(String::from(
495 /// "[2000s]
496 /// 2020 = bad"));
497 ///let outstring = config.writes();
498 ///```
499 ///Returns a `String` type contatining the ini-syntax file.
500 pub fn writesrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]writes().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
501 self.unparserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]unparse().()
502 }
503
504 ///Private function that converts the currently stored configuration into a valid ini-syntax string.
505 fn unparserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]unparse().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
506 // push key/value pairs in outmap to out string.
507 fn unparse_key_valuesrust-analyzer cargo configparser 3.0.3 ini/unparse_key_values().(
508 out: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
509 outmap: &Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
510 multiline: bool,
511 ) {
512 for (key, val) in outmap.iterrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]iter().() {
513 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(key);
514
515 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = val {
516 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('=');
517
518 if multiline {
519 let mut lines = value.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().();
520
521 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(lines.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Lines<'a>`][Iterator]next().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().());
522
523 for line in lines {
524 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING.);
525 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(" ");
526 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(line);
527 }
528 } else {
529 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(value);
530 }
531 }
532
533 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING.);
534 }
535 }
536
537 let mut out = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
538
539 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(defaultmap) = self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section.) {
540 unparse_key_valuesrust-analyzer cargo configparser 3.0.3 ini/unparse_key_values().(&mut out, defaultmap, self.multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline.);
541 }
542
543 for (section, secmap) in self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..iterrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]iter().() {
544 if section rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().&self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section. {
545 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(out, "[{}]", section).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
546 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING.);
547 unparse_key_valuesrust-analyzer cargo configparser 3.0.3 ini/unparse_key_values().(&mut out, secmap, self.multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline.);
548 }
549 }
550 out
551 }
552
553 ///Private function that parses ini-style syntax into a Map.
554 fn parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(&self, input: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
555 let mut map: Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>> = Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().();
556 let mut section = self.default_sectionrust-analyzer cargo configparser 3.0.3 ini/Ini#default_section..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().();
557 let mut current_key: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
558
559 let caser = |val: &str| {
560 if self.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive. {
561 val.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
562 } else {
563 val.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()
564 }
565 };
566
567 for (num, raw_line) in input.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
568 let line = match raw_line.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c: char| self.comment_symbolsrust-analyzer cargo configparser 3.0.3 ini/Ini#comment_symbols..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&c)) {
569 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx) => &raw_line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
570 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => raw_line,
571 };
572
573 let trimmed = line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
574
575 if trimmed.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
576 continue;
577 }
578
579 match (trimmed.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('['), trimmed.rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().(']')) {
580 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end)) => {
581 section = caser(trimmed[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().());
582
583 continue;
584 }
585 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
586 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
587 "line {}: Found opening bracket for section name but no closing bracket",
588 num
589 ));
590 }
591 _ => {}
592 }
593
594 if line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) && self.multilinerust-analyzer cargo configparser 3.0.3 ini/Ini#multiline. {
595 let key = match current_key.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
596 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x,
597 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
598 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
599 "line {}: Started with indentation but there is no current entry",
600 num,
601 ))
602 }
603 };
604
605 let valmap = map.entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(section.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()).or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().);
606
607 let val = valmap
608 .entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())
609 .or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(|| Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()));
610
611 match val {
612 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => {
613 x.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING.);
614 x.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(trimmed);
615 }
616 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
617 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().val = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", LINE_ENDINGrust-analyzer cargo configparser 3.0.3 ini/LINE_ENDING., trimmed));
618 }
619 }
620
621 continue;
622 }
623
624 let valmap = map.entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(section.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()).or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().);
625
626 match trimmed.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(&self.delimitersrust-analyzer cargo configparser 3.0.3 ini/Ini#delimiters.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) {
627 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delimiter) => {
628 let key = caser(trimmed[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#delimiter]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().());
629
630 if key.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
631 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("line {}:{}: Key cannot be empty", num, delimiter));
632 } else {
633 current_key = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
634
635 let value = trimmed[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().delimiter rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
636
637 valmap.insertrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]insert().(key, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value));
638 }
639 }
640 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
641 let key = caser(trimmed);
642 current_key = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
643
644 valmap.insertrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]insert().(key, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
645 }
646 }
647 }
648
649 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map)
650 }
651
652 ///Private function that cases things automatically depending on the set variable.
653 fn autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(&self, section: &str, key: &str) -> (Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) {
654 if self.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive. {
655 (section.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), key.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())
656 } else {
657 (section.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().(), key.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().())
658 }
659 }
660
661 ///Returns a clone of the stored value from the key stored in the defined section.
662 ///Unlike accessing the map directly, `get()` can process your input to make case-insensitive access *if* the
663 ///default constructor is used.
664 ///All `get` functions will do this automatically under the hood.
665 ///## Example
666 ///```rust
667 ///use configparser::ini::Ini;
668 ///
669 ///let mut config = Ini::new();
670 ///config.load("tests/test.ini");
671 ///let value = config.get("default", "defaultvalues").unwrap();
672 ///assert_eq!(value, String::from("defaultvalues"));
673 ///```
674 ///Returns `Some(value)` of type `String` if value is found or else returns `None`.
675 pub fn getrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]get().(&self, section: &str, key: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
676 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
677 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()
678 }
679
680 ///Parses the stored value from the key stored in the defined section to a `bool`.
681 ///For ease of use, the function converts the type case-insensitively (`true` == `True`).
682 ///## Example
683 ///```rust
684 ///use configparser::ini::Ini;
685 ///
686 ///let mut config = Ini::new();
687 ///config.load("tests/test.ini");
688 ///let value = config.getbool("values", "bool").unwrap().unwrap();
689 ///assert!(value); // value accessible!
690 ///```
691 ///Returns `Ok(Some(value))` of type `bool` if value is found or else returns `Ok(None)`.
692 ///If the parsing fails, it returns an `Err(string)`.
693 pub fn getboolrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]getbool().(&self, section: &str, key: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
694 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
695 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section) {
696 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => match secmap.getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key) {
697 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => match val {
698 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) => match inner.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<bool>() {
699 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
700 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(boolean) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(boolean)),
701 },
702 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
703 },
704 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
705 },
706 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
707 }
708 }
709
710 ///Parses the stored value from the key stored in the defined section to a `bool`. For ease of use, the function converts the type coerces a match.
711 ///It attempts to case-insenstively find `true`, `yes`, `t`, `y`, `1` and `on` to parse it as `True`.
712 ///Similarly it attempts to case-insensitvely find `false`, `no`, `f`, `n`, `0` and `off` to parse it as `False`.
713 ///## Example
714 ///```rust
715 ///use configparser::ini::Ini;
716 ///
717 ///let mut config = Ini::new();
718 ///config.load("tests/test.ini");
719 ///let value = config.getboolcoerce("values", "boolcoerce").unwrap().unwrap();
720 ///assert!(!value); // value accessible!
721 ///```
722 ///Returns `Ok(Some(value))` of type `bool` if value is found or else returns `Ok(None)`.
723 ///If the parsing fails, it returns an `Err(string)`.
724 pub fn getboolcoercerust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]getboolcoerce().(&self, section: &str, key: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
725 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
726 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section) {
727 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => match secmap.getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key) {
728 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => match val {
729 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) => {
730 let boolval = &inner.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().;
731 if self
732 .boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values.
733 .getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&true)
734 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
735 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
736 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|elem| elem rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().boolval)
737 {
738 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true))
739 } else if self
740 .boolean_valuesrust-analyzer cargo configparser 3.0.3 ini/Ini#boolean_values.
741 .getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&false)
742 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
743 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
744 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|elem| elem rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().boolval)
745 {
746 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false))
747 } else {
748 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
749 "Unable to parse value into bool at {}:{}",
750 section, key
751 ))
752 }
753 }
754 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
755 },
756 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
757 },
758 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
759 }
760 }
761
762 ///Parses the stored value from the key stored in the defined section to an `i64`.
763 ///## Example
764 ///```rust
765 ///use configparser::ini::Ini;
766 ///
767 ///let mut config = Ini::new();
768 ///config.load("tests/test.ini");
769 ///let value = config.getint("values", "int").unwrap().unwrap();
770 ///assert_eq!(value, -31415); // value accessible!
771 ///```
772 ///Returns `Ok(Some(value))` of type `i64` if value is found or else returns `Ok(None)`.
773 ///If the parsing fails, it returns an `Err(string)`.
774 pub fn getintrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]getint().(&self, section: &str, key: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i64>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
775 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
776 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section) {
777 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => match secmap.getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key) {
778 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => match val {
779 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) => match inner.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i64>() {
780 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
781 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(int) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(int)),
782 },
783 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
784 },
785 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
786 },
787 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
788 }
789 }
790
791 ///Parses the stored value from the key stored in the defined section to a `u64`.
792 ///## Example
793 ///```rust
794 ///use configparser::ini::Ini;
795 ///
796 ///let mut config = Ini::new();
797 ///config.load("tests/test.ini");
798 ///let value = config.getint("values", "Uint").unwrap().unwrap();
799 ///assert_eq!(value, 31415); // value accessible!
800 ///```
801 ///Returns `Ok(Some(value))` of type `u64` if value is found or else returns `Ok(None)`.
802 ///If the parsing fails, it returns an `Err(string)`.
803 pub fn getuintrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]getuint().(&self, section: &str, key: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
804 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
805 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section) {
806 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => match secmap.getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key) {
807 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => match val {
808 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) => match inner.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u64>() {
809 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
810 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(uint) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(uint)),
811 },
812 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
813 },
814 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
815 },
816 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
817 }
818 }
819
820 ///Parses the stored value from the key stored in the defined section to a `f64`.
821 ///## Example
822 ///```rust
823 ///use configparser::ini::Ini;
824 ///
825 ///let mut config = Ini::new();
826 ///config.load("tests/test.ini");
827 ///let value = config.getfloat("values", "float").unwrap().unwrap();
828 ///assert_eq!(value, 3.1415); // value accessible!
829 ///```
830 ///Returns `Ok(Some(value))` of type `f64` if value is found or else returns `Ok(None)`.
831 ///If the parsing fails, it returns an `Err(string)`.
832 pub fn getfloatrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]getfloat().(&self, section: &str, key: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f64>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
833 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
834 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&section) {
835 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => match secmap.getrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get().(&key) {
836 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => match val {
837 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) => match inner.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f64>() {
838 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
839 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(float) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(float)),
840 },
841 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
842 },
843 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
844 },
845 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
846 }
847 }
848
849 ///Returns a clone of the `Map` stored in our struct.
850 ///## Example
851 ///```rust
852 ///use configparser::ini::Ini;
853 ///
854 ///let mut config = Ini::new();
855 ///config.read(String::from(
856 /// "[section]
857 /// key=values"));
858 ///let map = config.get_map().unwrap();
859 ///assert_eq!(map, *config.get_map_ref()); // the cloned map is basically a snapshot that you own
860 ///```
861 ///Returns `Some(map)` if map is non-empty or else returns `None`.
862 ///Similar to `load()` but returns an `Option` type with the currently stored `Map`.
863 pub fn get_maprust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]get_map().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>> {
864 if self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..is_emptyrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]is_empty().() {
865 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
866 } else {
867 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
868 }
869 }
870
871 ///Returns an immutable reference to the `Map` stored in our struct.
872 ///## Example
873 ///```rust
874 ///use configparser::ini::Ini;
875 ///
876 ///let mut config = Ini::new();
877 ///let mapclone = config.read(String::from
878 /// ("[topsecrets]
879 /// Valueless key")).unwrap();
880 /////Think of the clone as being a snapshot at a point of time while the reference always points to the current configuration.
881 ///assert_eq!(*config.get_map_ref(), mapclone); // same as expected.
882 ///```
883 ///If you just need to definitely mutate the map, use `get_mut_map()` instead. Alternatively, you can generate a snapshot by getting a clone
884 ///with `get_map()` and work with that.
885 pub fn get_map_refrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]get_map_ref().(&self) -> &Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>> {
886 &self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.
887 }
888
889 ///Returns a mutable reference to the `Map` stored in our struct.
890 ///## Example
891 ///```rust
892 ///use configparser::ini::Ini;
893 ///
894 ///let mut config = Ini::new();
895 ///config.read(String::from
896 /// ("[topsecrets]
897 /// Valueless key"));
898 /////We can then get the mutable map and insert a value like:
899 ///config.get_mut_map().get_mut("topsecrets").unwrap().insert(String::from("nuclear launch codes"), None);
900 ///assert_eq!(config.get("topsecrets", "nuclear launch codes"), None); // inserted successfully!
901 ///```
902 ///If you just need to access the map without mutating, use `get_map_ref()` or make a clone with `get_map()` instead.
903 pub fn get_mut_maprust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]get_mut_map().(&mut self) -> &mut Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>> {
904 &mut self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.
905 }
906
907 ///Sets an `Option<String>` in the `Map` stored in our struct. If a particular section or key does not exist, it will be automatically created.
908 ///An existing value in the map will be overwritten. You can also set `None` safely.
909 ///## Example
910 ///```rust
911 ///use configparser::ini::Ini;
912 ///
913 ///let mut config = Ini::new();
914 ///config.read(String::from(
915 /// "[section]
916 /// key=value"));
917 ///let key_value = String::from("value");
918 ///config.set("section", "key", Some(key_value));
919 ///config.set("section", "key", None); // also valid!
920 ///assert_eq!(config.get("section", "key"), None); // correct!
921 ///```
922 ///Returns `None` if there is no existing value, else returns `Some(Option<String>)`, with the existing value being the wrapped `Option<String>`.
923 ///If you want to insert using a string literal, use `setstr()` instead.
924 pub fn setrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]set().(
925 &mut self,
926 section: &str,
927 key: &str,
928 value: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
929 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
930 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
931 match self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..get_mutrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get_mut().(&section) {
932 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secmap) => secmap.insertrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]insert().(key, value),
933 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
934 let mut valmap: Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> = Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().();
935 valmap.insertrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]insert().(key, value);
936 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..insertrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]insert().(section, valmap);
937 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
938 }
939 }
940 }
941
942 ///Sets an `Option<&str>` in the `Map` stored in our struct. If a particular section or key does not exist, it will be automatically created.
943 ///An existing value in the map will be overwritten. You can also set `None` safely.
944 ///## Example
945 ///```rust
946 ///use configparser::ini::Ini;
947 ///
948 ///let mut config = Ini::new();
949 ///config.read(String::from(
950 /// "[section]
951 /// key=notvalue"));
952 ///config.setstr("section", "key", Some("value"));
953 ///config.setstr("section", "key", None); // also valid!
954 ///assert_eq!(config.get("section", "key"), None); // correct!
955 ///```
956 ///Returns `None` if there is no existing value, else returns `Some(Option<String>)`, with the existing value being the wrapped `Option<String>`.
957 ///If you want to insert using a `String`, use `set()` instead.
958 pub fn setstrrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]setstr().(
959 &mut self,
960 section: &str,
961 key: &str,
962 value: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
963 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
964 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
965 self.setrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]set().(&section, &key, value.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().))
966 }
967
968 ///Clears the map, removing all sections and properties from the hashmap. It keeps the allocated memory for reuse.
969 ///## Example
970 ///```rust
971 ///use configparser::ini::Ini;
972 ///
973 ///let mut config = Ini::new();
974 ///config.read(String::from(
975 /// "[section]
976 /// key=somevalue"));
977 ///config.clear();
978 ///assert!(config.get_map_ref().is_empty()); // our map is empty!
979 ///```
980 ///Returns nothing.
981 pub fn clearrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]clear().(&mut self) {
982 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clearrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]clear().();
983 }
984
985 ///Removes a section from the hashmap, returning the properties stored in the section if the section was previously in the map.
986 ///## Example
987 ///```rust
988 ///use configparser::ini::Ini;
989 ///
990 ///let mut config = Ini::new();
991 ///config.read(String::from(
992 /// "[section]
993 /// updog=whatsupdog"));
994 ///config.remove_section("section"); // this will return a cloned hashmap of the stored property
995 ///assert!(config.get_map_ref().is_empty()); // with the last section removed, our map is now empty!
996 ///```
997 ///Returns `Some(section_map)` if the section exists or else, `None`.
998 pub fn remove_sectionrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]remove_section().(&mut self, section: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>> {
999 let section = if self.case_sensitiverust-analyzer cargo configparser 3.0.3 ini/Ini#case_sensitive. {
1000 section.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
1001 } else {
1002 section.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()
1003 };
1004 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..removerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]remove().(&section)
1005 }
1006
1007 ///Removes a key from a section in the hashmap, returning the value attached to the key if it was previously in the map.
1008 ///## Example
1009 ///```rust
1010 ///use configparser::ini::Ini;
1011 ///
1012 ///let mut config = Ini::new();
1013 ///config.read(String::from(
1014 /// "[section]
1015 /// updog=whatsupdog
1016 /// [anothersection]
1017 /// updog=differentdog"));
1018 ///let val = config.remove_key("anothersection", "updog").unwrap().unwrap();
1019 ///assert_eq!(val, String::from("differentdog")); // with the last section removed, our map is now empty!
1020 ///```
1021 ///Returns `Some(Option<String>)` if the value exists or else, `None`.
1022 pub fn remove_keyrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]remove_key().(&mut self, section: &str, key: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
1023 let (section, key) = self.autocaserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]autocase().(section, key);
1024 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..get_mutrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]get_mut().(&section)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..removerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]remove().(&key)
1025 }
1026 }
1027
1028 #[cfg(feature = "async-std")]
1029 impl Inirust-analyzer cargo configparser 3.0.3 ini/Ini# {
1030 ///Loads a file asynchronously from a defined path, parses it and puts the hashmap into our struct.
1031 ///At one time, it only stores one configuration, so each call to `load()` or `read()` will clear the existing `Map`, if present.
1032 ///
1033 ///Usage is similar to `load`, but `.await` must be called after along with the usual async rules.
1034 ///
1035 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
1036 ///Use `get_mut_map()` if you want a mutable reference.
1037 pub async fn load_asyncrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]load_async().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<AsyncPathrust-analyzer cargo async-std 1.13.2 path/path/Path#>>(
1038 &mut self,
1039 path: T,
1040 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1041 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map. = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(match async_fsrust-analyzer cargo async-std 1.13.2 fs/::read_to_stringrust-analyzer cargo async-std 1.13.2 fs/read_to_string/read_to_string().(&path).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll(). {
1042 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
1043 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1044 "couldn't read {}: {}",
1045 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo async-std 1.13.2 path/path/impl#[Path]display().(),
1046 why
1047 ))
1048 }
1049 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s,
1050 }) {
1051 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
1052 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1053 "couldn't read {}: {}",
1054 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo async-std 1.13.2 path/path/impl#[Path]display().(),
1055 why
1056 ))
1057 }
1058 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
1059 };
1060 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
1061 }
1062
1063 ///Loads a file from a defined path, parses it and applies it to the existing hashmap in our struct.
1064 ///While `load_async()` will clear the existing `Map`, `load_and_append_async()` applies the new values on top
1065 ///of the existing hashmap, preserving previous values.
1066 ///
1067 ///Usage is similar to `load_and_append`, but `.await` must be called after along with the usual async rules.
1068 ///
1069 ///Returns `Ok(map)` with a clone of the stored `Map` if no errors are thrown or else `Err(error_string)`.
1070 ///Use `get_mut_map()` if you want a mutable reference.
1071 pub async fn load_and_append_asyncrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]load_and_append_async().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<AsyncPathrust-analyzer cargo async-std 1.13.2 path/path/Path#>>(
1072 &mut self,
1073 path: T,
1074 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1075 let loaded = match self.parserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]parse().(match async_fsrust-analyzer cargo async-std 1.13.2 fs/::read_to_stringrust-analyzer cargo async-std 1.13.2 fs/read_to_string/read_to_string().(&path).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll(). {
1076 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
1077 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1078 "couldn't read {}: {}",
1079 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo async-std 1.13.2 path/path/impl#[Path]display().(),
1080 why
1081 ))
1082 }
1083 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s,
1084 }) {
1085 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(why) => {
1086 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1087 "couldn't read {}: {}",
1088 &path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo async-std 1.13.2 path/path/impl#[Path]display().(),
1089 why
1090 ))
1091 }
1092 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(map) => map,
1093 };
1094
1095 for (section, section_map) in loaded.iterrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]iter().() {
1096 self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map.
1097 .entryrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`]entry().(section.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())
1098 .or_insert_withrust-analyzer cargo indexmap 2.14.0 map/entry/impl#[`Entry<'a, K, V>`]or_insert_with().(Maprust-analyzer cargo indexmap 2.14.0 map/IndexMap#::newrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V>`]new().)
1099 .extendrust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][`Extend<(K, V)>`]extend().(section_map.clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().());
1100 }
1101
1102 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.maprust-analyzer cargo configparser 3.0.3 ini/Ini#map..clonerust-analyzer cargo indexmap 2.14.0 map/impl#[`IndexMap<K, V, S>`][Clone]clone().())
1103 }
1104
1105 ///Writes the current configuation to the specified path asynchronously. If a file is not present, it is automatically created for you, if a file already
1106 ///exists, it is truncated and the configuration is written to it.
1107 ///
1108 ///Usage is the same as `write`, but `.await` must be called after along with the usual async rules.
1109 ///
1110 ///Returns a `std::io::Result<()>` type dependent on whether the write was successful or not.
1111 pub async fn write_asyncrust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]write_async().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(&self, path: T) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
1112 async_fsrust-analyzer cargo async-std 1.13.2 fs/::writerust-analyzer cargo async-std 1.13.2 fs/write/write().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), self.unparserust-analyzer cargo configparser 3.0.3 ini/impl#[Ini]unparse().()).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
1113 }
1114 }