pub fn parse_ini(text: &str) -> HashMap<String, HashMap<String, Option<String>>>Expand description
Parses an INI string into a simple nested map structure:
HashMap<section, HashMap<key, Option<value>>>.
Style/indentation are not preserved.
Examples found in repository?
examples/parse_ini.rs (line 15)
5fn main() {
6 let text = r#"
7[server]
8host = 127.0.0.1
9port = 8080
10
11[app]
12name = my-app
13"#;
14
15 let map = parse_ini(text);
16 println!("Sections: {:?}", map.keys().collect::<Vec<_>>());
17
18 if let Some(server) = map.get("server") {
19 println!(
20 "server.host = {:?}",
21 server.get("host").and_then(|v| v.as_deref())
22 );
23 println!(
24 "server.port = {:?}",
25 server.get("port").and_then(|v| v.as_deref())
26 );
27 }
28
29 let out = stringify_ini(&map);
30 println!("Stringify:\n{}", out);
31}