zonfig 0.1.0

A small dynamic configuration loader with file watching and hot reload support.
Documentation
use std::time::Duration;

use serde::Deserialize;
use zonfig::WatchOptions;

#[derive(Debug, Deserialize)]
struct AppConfig {
    host: String,
    port: u16,
}

#[tokio::main]
async fn main() -> Result<(), zonfig::Error> {
    let config = zonfig::watch_with_options::<AppConfig>(
        "fixtures/app.toml",
        WatchOptions::default().with_cooldown(Duration::from_secs(2)),
    )
    .await?;

    config.on_change(|config| {
        println!("config changed: {}:{}", config.host, config.port);
    });
    config.on_error(|error| {
        eprintln!("reload failed: {error}");
    });

    config.with(|config| {
        println!("initial config: {}:{}", config.host, config.port);
    });

    tokio::time::sleep(Duration::from_secs(10)).await;
    config.with(|config| {
        println!("final config: {}:{}", config.host, config.port);
    });

    Ok(())
}