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(filename, || {
12 return sectioned_defaults! {
13 {
14 "host" => "127.0.0.1",
15 "port" => "8080",
16 }
17 }
18 });
19
20 config.save(filename).expect("Failed to save config.");
21
22 println!("{config:#?}");
23}