pub struct FileWatcher<M: Send + 'static> { /* private fields */ }Expand description
A subscription that reports changes to one filesystem path.
The watcher polls the path’s metadata (modification time and size) every
interval (250 ms by default) and sends one message per observed
transition: FileEvent::Created, FileEvent::Modified or
FileEvent::Removed. Polling keeps the runtime free of platform
watcher dependencies and behaves the same everywhere; the trade-offs are
latency bounded by the interval and that an edit which leaves both size
and modification time unchanged within one interval is not reported (a
same-length rewrite on a filesystem with coarse timestamps). Watching a
directory reports changes to the directory entry itself (entries added
or removed), not edits inside nested files.
§Example
fn subscriptions(&self) -> Vec<Box<dyn Subscription<MyMsg>>> {
vec![file_watcher("config.toml", MyMsg::ConfigChanged)]
}Implementations§
Source§impl<M: Send + 'static> FileWatcher<M>
impl<M: Send + 'static> FileWatcher<M>
Sourcepub const DEFAULT_INTERVAL: Duration
pub const DEFAULT_INTERVAL: Duration
Default poll interval.
Sourcepub fn new(
path: impl Into<PathBuf>,
make_msg: impl Fn(FileEvent) -> M + Send + Sync + 'static,
) -> Self
pub fn new( path: impl Into<PathBuf>, make_msg: impl Fn(FileEvent) -> M + Send + Sync + 'static, ) -> Self
Watch path, turning each observed FileEvent into a message.
Sourcepub fn with_interval(self, interval: Duration) -> Self
pub fn with_interval(self, interval: Duration) -> Self
Set the poll interval (clamped to at least 1 ms).