basic_usage/
basic_usage.rs1#![allow(missing_docs)]
2#![allow(clippy::unwrap_used)]
3
4use cirious_codex_config::{format::ConfigFormat, Deserialize};
5
6#[derive(Debug, Deserialize)]
7struct AppSettings {
8 app_name: String,
9 debug_mode: bool,
10}
11
12fn main() {
13 let ron_content = r#"
14 (
15 app_name: "My Awesome App",
16 debug_mode: true,
17 )
18 "#;
19
20 std::env::set_var("APP_DEBUG_MODE", "false");
21
22 println!("Loading configuration...");
23
24 let result = cirious_codex_config::ConfigBuilder::new()
25 .add_source(ron_content, ConfigFormat::Ron)
26 .unwrap()
27 .value
28 .add_env_prefix("APP_")
29 .build::<AppSettings>();
30
31 match result {
32 Ok(ok_wrapper) => {
33 let settings = ok_wrapper.value;
34 println!("App Name: {}", settings.app_name);
35 println!("Debug Mode: {}", settings.debug_mode);
36 }
37 Err(e) => eprintln!("Failed: {e}"),
38 }
39}