load_file/load_file.rs
1use config_tools::{sectioned_defaults, Config};
2
3fn main() {
4 let filename = "load-file.ini";
5
6 // If you want to handle errors manually, use Config::load() instead.
7 // Returns Result<config_tools::Config, config_tools::Error>
8 // let config = Config::load(filename);
9
10 // Load and use defaults on failure
11 let config = Config::load_or_default(
12 filename,
13 sectioned_defaults! {
14 {
15 "host" => "127.0.0.1",
16 "port" => "8080",
17 }
18 },
19 );
20
21 config.save(filename).expect("Failed to save config.");
22
23 println!("{config:#?}");
24}