Crates.io | config_updater |
lib.rs | config_updater |
version | 0.1.0 |
source | src |
created_at | 2024-07-22 03:04:40.859212 |
updated_at | 2024-07-22 03:04:40.859212 |
description | Automatically detect file changes and update accordingly |
homepage | |
repository | https://github.com/0xlunar/config_updater |
max_upload_size | |
id | 1310761 |
size | 41,747 |
Easy to use configuration updater.
Automatically update your config when changes are made instead of restarting each time.
use serde::Deserialize;
use config_updater::ConfigMonitor;
#[derive(Deserialize)]
struct MyConfig {
id: u64,
}
#[tokio::main]
async fn main() {
let config_monitor: ConfigMonitor<MyConfig> = ConfigMonitor::new("./config.json", Some(30));
let my_config = config_monitor.data(); // Arc<Mutex<MyConfig>>
let config_handle = config_monitor.monitor();
let c_my_config = my_config.clone();
tokio::spawn(async {
// Do Something with c_my_config
let my_id = {
let lock = c_my_config.lock().await;
lock.id.clone();
};
println!("My ID: {}", my_id);
});
config_handle.await.unwrap();
}