pub trait Watcher {
// Required methods
fn new<F: EventHandler>(event_handler: F, config: Config) -> Result<Self>
where Self: Sized;
fn watch(
&mut self,
path: &Path,
recursive_mode: RecursiveMode,
) -> Result<()>;
fn unwatch(&mut self, path: &Path) -> Result<()>;
fn kind() -> WatcherKind
where Self: Sized;
// Provided method
fn configure(&mut self, _option: Config) -> Result<bool> { ... }
}
Expand description
Type that can deliver file activity notifications
Watcher is implemented per platform using the best implementation available on that platform. In addition to such event driven implementations, a polling implementation is also provided that should work on any platform.
Required Methods§
sourcefn new<F: EventHandler>(event_handler: F, config: Config) -> Result<Self>where
Self: Sized,
fn new<F: EventHandler>(event_handler: F, config: Config) -> Result<Self>where
Self: Sized,
Create a new watcher with an initial Config.
sourcefn watch(&mut self, path: &Path, recursive_mode: RecursiveMode) -> Result<()>
fn watch(&mut self, path: &Path, recursive_mode: RecursiveMode) -> Result<()>
Begin watching a new path.
If the path
is a directory, recursive_mode
will be evaluated. If recursive_mode
is
RecursiveMode::Recursive
events will be delivered for all files in that tree. Otherwise
only the directory and its immediate children will be watched.
If the path
is a file, recursive_mode
will be ignored and events will be delivered only
for the file.
On some platforms, if the path
is renamed or removed while being watched, behaviour may
be unexpected. See discussions in #165 and #166. If less surprising behaviour is wanted
one may non-recursively watch the parent directory as well and manage related events.
sourcefn unwatch(&mut self, path: &Path) -> Result<()>
fn unwatch(&mut self, path: &Path) -> Result<()>
Stop watching a path.
§Errors
Returns an error in the case that path
has not been watched or if removing the watch
fails.
sourcefn kind() -> WatcherKindwhere
Self: Sized,
fn kind() -> WatcherKindwhere
Self: Sized,
Returns the watcher kind, allowing to perform backend-specific tasks