Trait Watcher
trait Watcher
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
fn new<F: EventHandler>(event_handler: F, config: config::Config) -> Result<Self> where Self: SizedCreate a new watcher with an initial Config.
fn watch(self: &mut Self, path: &Path, recursive_mode: RecursiveMode) -> Result<()>Begin watching a new path.
If the
pathis a directory,recursive_modewill be evaluated. Ifrecursive_modeisRecursiveMode::Recursiveevents will be delivered for all files in that tree. Otherwise only the directory and its immediate children will be watched.If the
pathis a file,recursive_modewill be ignored and events will be delivered only for the file.On some platforms, if the
pathis 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.fn unwatch(self: &mut Self, path: &Path) -> Result<()>Stop watching a path.
Errors
Returns an error in the case that
pathhas not been watched or if removing the watch fails.fn kind() -> WatcherKind where Self: SizedReturns the watcher kind, allowing to perform backend-specific tasks
Provided Methods
fn paths_mut<'me>(self: &'me mut Self) -> Box<dyn PathsMut + 'me>Add/remove paths to watch.
For some watcher implementations this method provides better performance than multiple calls to
Watcher::watchandWatcher::unwatchif you want to add/remove many paths at once.Examples
# use ; # use Path; #fn configure(self: &mut Self, _option: Config) -> Result<bool>Configure the watcher at runtime.
See the
Configstruct for all configuration options.Returns
Ok(true)on success.Ok(false)if the watcher does not support or implement the option.Err(notify::Error)on failure.
Implementors
impl Watcher for NullWatcherimpl Watcher for PollWatcherimpl Watcher for INotifyWatcher