pub struct Watcher { /* private fields */ }Expand description
A watcher that monitors files for changes and debounces events.
The Watcher struct is responsible for setting up a file watcher and debouncing
file change events. It uses the notify crate to watch for file changes, and the
notify-debouncer-full crate to debounce those events.
Implementations§
Source§impl Watcher
impl Watcher
Sourcepub fn new(handler: impl DebounceEventHandler) -> Self
pub fn new(handler: impl DebounceEventHandler) -> Self
Creates a new file watcher with the provided debounce event handler.
The file watcher will debounce events for 2 seconds before triggering the provided handler. This helps to reduce the number of events that need to be processed, especially when many files are being watched and modified in quick succession.
§Arguments
handler- The debounce event handler to call when a file change is detected.
§Returns
A new instance of the file watcher.
Sourcepub fn watch(&mut self, filename: &str) -> Result<(), Error>
pub fn watch(&mut self, filename: &str) -> Result<(), Error>
Watches the specified file for changes.
This function sets up a file watcher to monitor the specified file for any changes.
When a change is detected, the file is added to the debouncer’s cache to be processed later.
The function returns a Result indicating whether the file watcher was successfully set up.
§Arguments
filename- The path to the file to be watched.
§Returns
A Result containing either an empty () value on success, or an Error on failure.