pub struct ConfigWatcher<T> { /* private fields */ }Expand description
A handle to a configuration that is automatically reloaded when any of its source files change.
getreturns the current snapshot without locking, cheap enough to call on every request;- when a reload fails, the previous configuration stays active and the
error is reported through
on_error; - dropping the watcher stops the background thread.
Created by ConfigBuilder::watch.
Implementations§
Source§impl<T> ConfigWatcher<T>
impl<T> ConfigWatcher<T>
Sourcepub fn get(&self) -> Arc<T> ⓘ
pub fn get(&self) -> Arc<T> ⓘ
Returns the currently active configuration snapshot.
Lock-free (backed by arc-swap), so it can be called freely on hot
paths and from any thread. The returned Arc stays valid even if
the configuration is swapped out in the meantime.
Sourcepub fn on_change(&self, callback: impl Fn(Arc<T>) + Send + Sync + 'static)
pub fn on_change(&self, callback: impl Fn(Arc<T>) + Send + Sync + 'static)
Registers a callback invoked after each successful reload with the new configuration.
Callbacks may be registered multiple times and run on the background watcher thread — keep them short and non-blocking. A callback that panics will terminate that thread and stop hot reloading.
Trait Implementations§
Source§impl<T> Drop for ConfigWatcher<T>
impl<T> Drop for ConfigWatcher<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for ConfigWatcher<T>
impl<T> !UnwindSafe for ConfigWatcher<T>
impl<T> Freeze for ConfigWatcher<T>
impl<T> Send for ConfigWatcher<T>
impl<T> Sync for ConfigWatcher<T>
impl<T> Unpin for ConfigWatcher<T>
impl<T> UnsafeUnpin for ConfigWatcher<T>
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