Skip to main content

FilesystemPoller

Struct FilesystemPoller 

Source
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

Source

pub fn new(poll_interval: Duration) -> Self

Create a poller with an explicit throttling interval.

Source

pub fn with_default_interval() -> Self

Create a poller using the default 250 ms throttling interval.

Source

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.

Source

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.

Source

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.

Source

pub fn watched_paths(&self) -> Vec<PathBuf>

Return all currently watched paths, sorted ascending for deterministic diagnostics.

Source

pub fn watched_count(&self) -> usize

Number of paths currently being watched.

Source

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.

Source

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.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more