load_file/
load_file.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use config_tools::{sectioned_defaults, Config};

fn main() {
    let filename = "load-file.ini";

    // If you want to handle errors manually, use Config::load() instead.
    // Returns Result<config_tools::Config, config_tools::Error>
    // let config = Config::load(filename);

    // Load and use defaults on failure
    let config = Config::load_or_default(filename, || sectioned_defaults! {
        {
            "host" => "127.0.0.1",
            "port" => "8080",
        }
    });

    config.save(filename).expect("Failed to save config.");

    println!("{config:#?}");
}