Crate notify [] [src]

Cross-platform file system notification library

The source code for this project can be found on GitHub.

Installation

Simply add notify to your Cargo.toml.

[dependencies]
notify = "^2.5.0"

Examples

Basic usage

extern crate notify;

use notify::{RecommendedWatcher, Error, Watcher};
use std::sync::mpsc::channel;

fn main() {
  // 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 w: Result<RecommendedWatcher, Error> = Watcher::new(tx);

  match w {
    Ok(mut watcher) => {
      // Add a path to be watched. All files and directories at that path and
      // below will be monitored for changes.
      watcher.watch("/home/test/notify");

      // You'll probably want to do that in a loop. The type to match for is
      // notify::Event, look at src/lib.rs for details.
      match rx.recv() {
        _ => println!("Recv.")
      }
    },
    Err(_) => println!("Error")
  }
}

Platforms

  • Linux / Android: inotify
  • OS X: FSEvent
  • Windows: ReadDirectoryChangesW
  • All platforms: polling

Limitations

FSEvent

Due to the inner security model of FSEvent (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

  • BSD / OS X / iOS: kqueue
  • Solaris 11: FEN

Pull requests and bug reports happily accepted!

Origins

Inspired by Go's fsnotify, 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.

Reexports

pub use self::op::Op;
pub use self::inotify::INotifyWatcher;
pub use self::null::NullWatcher;
pub use self::poll::PollWatcher;

Modules

inotify

Watcher implementation for the inotify Linux API

null

Stub Watcher implementation

op

Contains the Op type which describes the actions for which an event is delivered

poll

Generic Watcher implementation based on polling

Structs

Event

Event delivered when action occurs on a watched path

Enums

Error

Errors generated from the notify crate

Traits

Watcher

Type that can deliver file activity notifications

Functions

new

Convenience method for creating the RecommendedWatcher for the current platform

Type Definitions

RecommendedWatcher

The recommended Watcher implementation for the current platform

Result

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