Notify

Crate version Crate license Crate download count

Appveyor (Windows) Travis (Linux and OS X)

Code of Conduct Documentation

Cross-platform filesystem notification library for Rust.

As used by: [cargo watch], [cobalt], [handlebars-iron], [rdiff], and [watchexec]. (Want to be added to this list? Open a pull request!)

Installation

toml [dependencies] notify = "4.0.0"

Usage

```rust extern crate notify;

use notify::{RecommendedWatcher, Watcher, RecursiveMode}; use std::sync::mpsc::channel; use std::time::Duration;

fn watch() -> notify::Result<()> { // Create a channel to receive the events. let (tx, rx) = channel();

// Automatically select the best implementation for your platform.
// You can also access each implementation directly e.g. INotifyWatcher.
let mut watcher: RecommendedWatcher = try!(Watcher::new(tx, Duration::from_secs(2)));

// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
try!(watcher.watch("/home/test/notify", RecursiveMode::Recursive));

// This is a simple loop, but you may want to use more complex logic here,
// for example to handle I/O.
loop {
    match rx.recv() {
        Ok(event) => println!("{:?}", event),
        Err(e) => println!("watch error: {:?}", e),
    }
}

}

fn main() { if let Err(e) = watch() { println!("error: {:?}", e) } } ```

Version 2.x

The documentation for the previous major version is available on docs.rs. While version 2.x will no longer be maintained and we encourage all library authors to switch to version 3+ (a short guide is provided below), it is still a dependency of many packages. Here is a list of changes you may need to take note of:

To upgrade to Notify 3+ with minimal behaviour change:

Platforms

FSEvents

Due to the inner security model of FSEvents (see [FileSystemEventSecurity]), some event cannot be observed easily when trying to follow files that do not belong to you. In this case, reverting to the pollwatcher can fix the issue, with a slight performance cost.

Todo

Pull requests and bug reports happily accepted!

Origins

Inspired by Go's [fsnotify] and Node.js's [Chokidar], born out of need for [cargo watch], and general frustration at the non-existence of C/Rust cross-platform notify libraries.

Written by [Félix Saparelli] and awesome [contributors], and released in the Public Domain using the Creative Commons Zero Declaration.