pub struct FilesystemPoller { /* private fields */ }Expand description
Polls a set of filesystem paths for modification-time changes.
Each watched path is associated with the SystemTime of its last observed
modification. On every (un-throttled) poll the current mtime of each path
is compared against the recorded value to produce PolledChange events.
See the module documentation for the throttling and created-vs-modified semantics.
Implementations§
Source§impl FilesystemPoller
impl FilesystemPoller
Sourcepub fn new(poll_interval: Duration) -> Self
pub fn new(poll_interval: Duration) -> Self
Create a poller with an explicit throttling interval.
Sourcepub fn with_default_interval() -> Self
pub fn with_default_interval() -> Self
Create a poller using the default 250 ms throttling interval.
Sourcepub fn register_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn register_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Start watching path, seeding the modification-time table from the
file’s current mtime.
§Errors
Propagates any std::io::Error from reading the file’s metadata or
modification time — most commonly std::io::ErrorKind::NotFound when
the file does not exist. To watch a not-yet-created path use
Self::track_expected instead.
Sourcepub fn track_expected<P: AsRef<Path>>(&mut self, path: P)
pub fn track_expected<P: AsRef<Path>>(&mut self, path: P)
Track a path that may not exist yet.
The path is recorded with a SystemTime::UNIX_EPOCH sentinel so that
when the file later appears the next poll reports it as
PolledChangeKind::Created (rather than PolledChangeKind::Modified).
While the file is still absent the sentinel suppresses any
PolledChangeKind::Deleted event — the path simply waits to appear.
This also re-arms creation detection for a path that was previously
dropped after a deletion.
Sourcepub fn deregister_path<P: AsRef<Path>>(&mut self, path: P) -> bool
pub fn deregister_path<P: AsRef<Path>>(&mut self, path: P) -> bool
Stop watching path.
Returns true if the path was being watched, false otherwise.
Sourcepub fn watched_paths(&self) -> Vec<PathBuf>
pub fn watched_paths(&self) -> Vec<PathBuf>
Return all currently watched paths, sorted ascending for deterministic diagnostics.
Sourcepub fn watched_count(&self) -> usize
pub fn watched_count(&self) -> usize
Number of paths currently being watched.
Sourcepub fn poll(&mut self) -> Vec<PolledChange>
pub fn poll(&mut self) -> Vec<PolledChange>
Poll for changes, honouring the configured throttling interval.
If a previous poll occurred less than poll_interval ago this returns an
empty vector without touching the filesystem. Otherwise it records the
current instant and runs the full comparison.
Sourcepub fn force_poll(&mut self) -> Vec<PolledChange>
pub fn force_poll(&mut self) -> Vec<PolledChange>
Poll for changes immediately, ignoring the throttling interval.
The throttle clock is still updated so that a subsequent Self::poll
is measured relative to this call.