Crate notify[][src]

Expand description

Cross-platform file system notification library


notify = "5.0.0-pre.11"


Events are serialisable via serde if the serde feature is enabled:

notify = { version = "5.0.0-pre.11", features = ["serde"] }


use notify::{Watcher, RecommendedWatcher, RecursiveMode, Result};

fn main() -> Result<()> {
    // Automatically select the best implementation for your platform.
    let mut watcher = notify::recommended_watcher(|res| {
        match res {
           Ok(event) => println!("event: {:?}", event),
           Err(e) => println!("watch error: {:?}", e),

    // Add a path to be watched. All files and directories at that path and
    // below will be monitored for changes."."), RecursiveMode::Recursive)?;


With precise events

By default, Notify emits non-descript events containing only the affected path and some metadata. To get richer details about what the events are about, you need to enable Config::PreciseEvents. The full event classification is described in the event module documentation.

use notify::Config;

With different configurations

It is possible to create several watchers with different configurations or implementations that all call the same event function. This can accommodate advanced behaviour or work around limits.

      fn event_fn(res: Result<notify::Event>) {
          match res {
             Ok(event) => println!("event: {:?}", event),
             Err(e) => println!("watch error: {:?}", e),

      let mut watcher1 = notify::recommended_watcher(event_fn)?;
      let mut watcher2 = notify::recommended_watcher(event_fn)?;


pub use event::Event;
pub use event::EventKind;
pub use crate::inotify::INotifyWatcher;
pub use null::NullWatcher;
pub use poll::PollWatcher;


The Event type and the hierarchical EventKind descriptor.

Watcher implementation for the inotify Linux API

Stub Watcher implementation

Generic Watcher implementation based on polling


Notify error type.


Runtime configuration items for watchers.

Error kinds

Indicates whether only the provided directory or its sub-directories as well should be watched


The set of requirements for watcher event handling functions.

Type that can deliver file activity notifications


Convenience method for creating the RecommendedWatcher for the current platform in immediate mode.

Type Definitions

The recommended Watcher implementation for the current platform

Type alias to use this library’s Error type in a Result