from_section/
from_section.rs1#![allow(dead_code)]
2use config_tools::{sectioned_defaults, Config, FromSection, Section};
3
4#[derive(Debug, FromSection)]
5struct ServerSettings {
6 address: String,
7 port: u16,
8 threads: u16,
9}
10
11#[derive(Debug, FromSection)]
12struct LdapSettings {
13 host: String,
14 domain: String,
15}
16
17fn main() {
18 let config = Config::load_or_default(
19 "get-values.ini",
20 sectioned_defaults! {
21 {
22 "console" => "true",
23 "log_level" => "info",
24 }
25 ["Server"] {
26 "address" => "127.0.0.1",
27 "port" => "8080",
28 "threads" => "4",
29 }
30 ["LDAP"] {
31 "host" => "ldap://localhost:389",
32 "domain" => "example.com",
33 }
34 },
35 );
36
37 let ldap_settings = LdapSettings::from_section(&config.section("LDAP").unwrap()).unwrap();
38 let server_settings = ServerSettings::from_section(&config.section("Server").unwrap()).unwrap();
39
40 println!("{ldap_settings:#?}");
41 println!("{server_settings:#?}");
42}