use dotcfg::DotCfg;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Default)]
struct AppConfig {
theme: String,
language: String,
notifications: bool,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg = DotCfg::new("myapp");
let config: AppConfig = cfg.load_or_default()?;
println!("Current config: {config:#?}");
println!("Config file: {:?}", cfg.file_path()?);
cfg.set("theme", "dark")?;
println!("theme = {}", cfg.get("theme")?);
#[cfg(feature = "yaml")]
{
let ycfg = DotCfg::new("myapp").yaml();
let yconfig: AppConfig = ycfg.load_or_default()?;
println!("YAML config: {yconfig:#?}");
println!("YAML file: {:?}", ycfg.file_path()?);
ycfg.set("language", "en")?;
println!("language = {}", ycfg.get("language")?);
}
Ok(())
}