1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use config_lib::Config;
fn main() {
let content = r#"
# Basic configuration
app_name = "test-app"
port = 8080
debug = true
version = 1.0
# Section
[database]
host = "localhost"
port = 5432
# Arrays
servers = alpha beta gamma
ports = 8001 8002 8003
"#;
match Config::from_string(content, Some("conf")) {
Ok(config) => {
println!("Success! Parsed config");
println!("Root level keys:");
// Check for servers in root
match config.get("servers") {
Some(value) => println!("Found servers in root: {value:?}"),
None => println!("servers not found in root"),
}
// Check for servers in database section
match config.get("database.servers") {
Some(value) => println!("Found servers in database: {value:?}"),
None => println!("servers not found in database section"),
}
// Check for ports in database section
match config.get("database.ports") {
Some(value) => println!("Found ports in database: {value:?}"),
None => println!("ports not found in database section"),
}
}
Err(e) => {
println!("Error: {e:?}");
}
}
}