Trait notify::Watcher[][src]

pub trait Watcher: Sized {
    fn new_raw(tx: Sender<RawEvent>) -> Result<Self>;
fn new(tx: Sender<DebouncedEvent>, delay: Duration) -> Result<Self>;
fn watch<P: AsRef<Path>>(
        &mut self,
        path: P,
        recursive_mode: RecursiveMode
    ) -> Result<()>;
fn unwatch<P: AsRef<Path>>(&mut self, path: P) -> Result<()>; }

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_raw(tx: Sender<RawEvent>) -> Result<Self>[src]

Create a new watcher in raw mode.

Events will be sent using the provided tx immediately after they occurred.

fn new(tx: Sender<DebouncedEvent>, delay: Duration) -> Result<Self>[src]

Create a new debounced watcher with a delay.

Events won’t be sent immediately but after the specified delay.

Advantages

This has the advantage that a lot of logic can be offloaded to notify.

For example you won’t have to handle RENAME events yourself by piecing the two parts of rename events together. Instead you will just receive a Rename{from: PathBuf, to: PathBuf} event.

Also notify will detect the beginning and the end of write operations. As soon as something is written to a file, a NoticeWrite event is emitted. If no new event arrived until after the specified delay, a Write event is emitted.

A practical example would be the safe-saving of a file, where a temporary file is created and written to, then only when everything has been written to that file is it renamed to overwrite the file that was meant to be saved. Instead of receiving a CREATE event for the temporary file, WRITE events to that file and a RENAME event from the temporary file to the file being saved, you will just receive a single Write event.

If you use a delay of more than 30 seconds, you can avoid receiving repetitions of previous events on macOS.

Disadvantages

Your application might not feel as responsive.

If a file is saved very slowly, you might receive a Write event even though the file is still being written to.

fn watch<P: AsRef<Path>>(
    &mut self,
    path: P,
    recursive_mode: RecursiveMode
) -> Result<()>
[src]

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.

fn unwatch<P: AsRef<Path>>(&mut self, path: P) -> Result<()>[src]

Stop watching a path.

Errors

Returns an error in the case that path has not been watched or if removing the watch fails.

Loading content...

Implementors

impl Watcher for INotifyWatcher[src]

impl Watcher for NullWatcher[src]

impl Watcher for PollWatcher[src]

Loading content...