pub struct Watcher<F, Fut>{ /* private fields */ }Expand description
A file watcher that monitors changes in a list of files and triggers a callback when changes are detected.
§Generics
F: A closure or function that takes aSnapshotand produces a future.Fut: The type of the future returned by the callback.
§Fields
files: A list ofFileInfocontaining metadata about the monitored files.callback: A closure or function to execute when changes are detected.poll_interval: The interval (in milliseconds) at which files are polled for changes.
Implementations§
Source§impl<F, Fut> Watcher<F, Fut>
impl<F, Fut> Watcher<F, Fut>
Sourcepub async fn new(
paths: Vec<PathBuf>,
poll_interval: u64,
callback: F,
) -> Result<Self, Error>
pub async fn new( paths: Vec<PathBuf>, poll_interval: u64, callback: F, ) -> Result<Self, Error>
Creates a new Watcher instance.
§Parameters
paths: A list of paths to the files to monitor.poll_interval: The interval (in milliseconds) at which files are polled for changes.callback: A closure or function to execute when changes are detected.
§Returns
Ok(Self): A new instance ofWatcherif all files are successfully initialized.Err(Error): An error if any file cannot be initialized (e.g., failed to read metadata).
§Errors
- Returns an error with
ErrorKind::ErrorInitializingWatcherif a file’s metadata cannot be read.
Sourcepub async fn watch(&mut self) -> Result<(), Error>
pub async fn watch(&mut self) -> Result<(), Error>
Starts monitoring the files for changes.
§Behavior
- Periodically checks the modification time of each file.
- If any file has been modified since the last check, triggers the
callbackwith aSnapshot. - Continues indefinitely until the task is canceled.
§Returns
Ok(()): This function only exits if the task is canceled or an error occurs.Err(Error): An error if reading a file’s metadata or content fails.
§Errors
- Returns an error with
ErrorKind::ErrorReadingFileif file metadata or content cannot be read.
Auto Trait Implementations§
impl<F, Fut> Freeze for Watcher<F, Fut>where
F: Freeze,
impl<F, Fut> RefUnwindSafe for Watcher<F, Fut>where
F: RefUnwindSafe,
impl<F, Fut> Send for Watcher<F, Fut>where
F: Send,
impl<F, Fut> Sync for Watcher<F, Fut>where
F: Sync,
impl<F, Fut> Unpin for Watcher<F, Fut>where
F: Unpin,
impl<F, Fut> UnwindSafe for Watcher<F, Fut>where
F: UnwindSafe,
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