Skip to main content

HotReloadConfig

Struct HotReloadConfig 

Source
pub struct HotReloadConfig { /* private fields */ }
Expand description

Hot-reloadable configuration container.

Construct with HotReloadConfig::from_file, then either drive reloads manually with HotReloadConfig::reload or hand off to a background watcher with HotReloadConfig::start_watching.

Configurable knobs (all consuming-builder style, intended for fluent construction):

Implementations§

Source§

impl HotReloadConfig

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new hot-reloadable configuration from a file.

§Errors

Returns an error if the file cannot be read, parsed, or stat’d for its modification time.

Source

pub fn with_poll_interval(self, interval: Duration) -> Self

Set the polling interval for file change detection.

When the hot-reload feature is enabled (the default in v0.9.6+), the primary watcher is event-driven and this interval is only consulted as the watchdog cadence if with_polling_fallback has been called.

When the hot-reload feature is disabled, this is the actual polling cadence of the background thread.

Source

pub fn with_debounce(self, debounce: Duration) -> Self

Override the debounce window applied to clustered file-change events.

Editors that save via “write-to-tmp + atomic-rename” generate multiple kernel events for a single user save. The debounce collapses any burst within this window to a single reload. Default: 100 ms.

Source

pub fn with_polling_fallback(self) -> Self

Opt into running a polling watchdog in addition to the event-driven watcher.

Network filesystems (SMB, NFS), some container overlay filesystems, and a handful of edge-case kernel configurations drop or delay events that notify would normally surface. Enabling the polling fallback re-derives changes from periodic stat(2) calls on the watched path, at the HotReloadConfig::with_poll_interval cadence.

Has no effect (and costs nothing) when the hot-reload Cargo feature is disabled — the watcher is already polling in that configuration.

Source

pub fn with_change_notifications(self) -> (Self, Receiver<ConfigChangeEvent>)

Enable change notifications.

Returns the configured HotReloadConfig together with a Receiver that will deliver ConfigChangeEvents as the watcher observes them.

Source

pub fn config(&self) -> Arc<RwLock<Config>>

Get a thread-safe reference to the current configuration.

Source

pub fn snapshot(&self) -> Result<Config>

Get a freshly-reparsed snapshot of the configuration file as it exists on disk right now.

This is distinct from reading the current Arc<RwLock<Config>> — it bypasses the watcher and re-reads the file. Useful for “what would I see if I reloaded now” inspection.

§Errors

Returns an error if the file cannot be read or parsed.

Source

pub fn reload(&mut self) -> Result<bool>

Manually trigger a reload check.

Re-stats the file, compares mtime against the last-known modification time, and re-parses if newer. Sends a ConfigChangeEvent::Reloaded or ConfigChangeEvent::ReloadFailed notification if change notifications are enabled.

Returns Ok(true) if a reload was performed, Ok(false) if the file was unchanged since the last check.

§Errors

Returns an error if the file cannot be stat’d, read, or parsed.

Source

pub fn start_watching(self) -> HotReloadHandle

Start automatic hot reloading in a background thread.

With the hot-reload Cargo feature enabled (the default in v0.9.6+), the background worker registers a notify::RecommendedWatcher on the file’s parent directory and reacts to kernel events. Otherwise it falls back to a poll_interval-cadence polling thread (the v0.9.5 behavior).

Source

pub fn file_path(&self) -> &Path

Get the file path being watched.

Source

pub fn last_modified(&self) -> SystemTime

Get the last modification time.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.