pub struct ConfigWatcher { /* private fields */ }Expand description
A config file watcher that reloads on changes.
Uses notify for filesystem events and debounces rapid changes.
Invalid config files are rejected — the last valid config is preserved.
Implementations§
Source§impl ConfigWatcher
impl ConfigWatcher
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self, ConfigError>
pub fn new(path: impl AsRef<Path>) -> Result<Self, ConfigError>
Create a new ConfigWatcher for the given config file.
Loads the initial config from the file. Returns an error if the initial load fails.
Sourcepub fn subscribe(&self) -> Receiver<Arc<ForgeConfig>>
pub fn subscribe(&self) -> Receiver<Arc<ForgeConfig>>
Get a receiver that yields the latest config on each change.
Sourcepub fn current(&self) -> Arc<ForgeConfig>
pub fn current(&self) -> Arc<ForgeConfig>
Get the current config.
Sourcepub fn start(self) -> JoinHandle<()>
pub fn start(self) -> JoinHandle<()>
Start watching the config file for changes.
Returns a JoinHandle for the background task. The task runs until
the watcher is dropped or the file becomes unwatchable.
Auto Trait Implementations§
impl Freeze for ConfigWatcher
impl !RefUnwindSafe for ConfigWatcher
impl Send for ConfigWatcher
impl Sync for ConfigWatcher
impl Unpin for ConfigWatcher
impl UnsafeUnpin for ConfigWatcher
impl !UnwindSafe for ConfigWatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more