use conferencier::{ConfigScope, ConfigStore, Result};
#[derive(ConfigScope)]
#[confer(section = "App")]
struct AppSettings {
port: u16,
#[confer(default = "localhost".into())]
host: String,
banner: Option<String>,
}
#[tokio::main]
async fn main() -> Result<()> {
let store = ConfigStore::from_str(
r#"[App]
port = 8080
banner = "Welcome!"
"#,
)?;
let scope = AppSettings::from_store(&store)?;
{
let guard = scope.read().await;
println!("Initial host: {}", guard.host);
println!("Initial port: {}", guard.port);
println!("Banner: {:?}", guard.banner);
}
{
let mut guard = scope.write().await;
guard.host = "127.0.0.1".into();
guard.banner = None; }
AppSettings::save(&scope, &store).await?;
let serialized = store.save_str()?;
println!("Updated TOML:\n{}", serialized);
Ok(())
}