feat: hot-reloading of config file

This commit is contained in:
Jun Kurihara 2023-07-23 01:42:39 +09:00
commit 58e22d33af
No known key found for this signature in database
GPG key ID: 6D3FEE70E498C15B
16 changed files with 213 additions and 58 deletions

View file

@ -0,0 +1,24 @@
use super::toml::ConfigToml;
use async_trait::async_trait;
use hot_reload::{Reload, ReloaderError};
#[derive(Clone)]
pub struct ConfigTomlReloader {
pub config_path: String,
}
#[async_trait]
impl Reload<ConfigToml> for ConfigTomlReloader {
type Source = String;
async fn new(source: &Self::Source) -> Result<Self, ReloaderError<ConfigToml>> {
Ok(Self {
config_path: source.clone(),
})
}
async fn reload(&self) -> Result<Option<ConfigToml>, ReloaderError<ConfigToml>> {
let conf = ConfigToml::new(&self.config_path)
.map_err(|_e| ReloaderError::<ConfigToml>::Reload("Failed to reload config toml"))?;
Ok(Some(conf))
}
}