pub struct KernelConfigWatcher { /* private fields */ }Expand description
A poll-based config file watcher that detects changes and applies them without requiring a restart.
It polls the file’s mtime every 5 seconds, re-reads and validates on change, and notifies registered callbacks with the new config and a diff summary.
Implementations§
Source§impl KernelConfigWatcher
impl KernelConfigWatcher
Sourcepub fn new(config_path: PathBuf, initial_config: PunchConfig) -> Self
pub fn new(config_path: PathBuf, initial_config: PunchConfig) -> Self
Create a new watcher for the given config file path with an initial config.
Sourcepub async fn on_change<F>(&self, callback: F)
pub async fn on_change<F>(&self, callback: F)
Register a callback that will be invoked when the config changes.
Multiple callbacks can be registered. They are called in registration order with a reference to the new config and the diff summary.
Sourcepub async fn current_config(&self) -> PunchConfig
pub async fn current_config(&self) -> PunchConfig
Get a clone of the current config.
Sourcepub fn config_arc(&self) -> Arc<RwLock<PunchConfig>>
pub fn config_arc(&self) -> Arc<RwLock<PunchConfig>>
Get a shared reference to the underlying config Arc.
Sourcepub fn watch(&self) -> JoinHandle<()>
pub fn watch(&self) -> JoinHandle<()>
Start the poll loop. Returns a JoinHandle for the spawned task.
The task checks the config file’s mtime every 5 seconds. On change:
- Reads and parses the file as TOML
- Validates the new config (keeps old config on error)
- Computes the diff and logs changes
- Warns about non-reloadable changes
- Swaps the config under the
RwLock - Notifies all registered callbacks
Auto Trait Implementations§
impl !Freeze for KernelConfigWatcher
impl !RefUnwindSafe for KernelConfigWatcher
impl Send for KernelConfigWatcher
impl Sync for KernelConfigWatcher
impl Unpin for KernelConfigWatcher
impl UnsafeUnpin for KernelConfigWatcher
impl !UnwindSafe for KernelConfigWatcher
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more