11 unstable releases (5 breaking)

new 0.6.0 Jan 10, 2025
0.5.0 Oct 25, 2024
0.4.1 Aug 21, 2023
0.3.0 May 17, 2023
0.1.3 Aug 17, 2022

#492 in Filesystem

Download history 42295/week @ 2024-09-21 37427/week @ 2024-09-28 39285/week @ 2024-10-05 42538/week @ 2024-10-12 41062/week @ 2024-10-19 36216/week @ 2024-10-26 37722/week @ 2024-11-02 32592/week @ 2024-11-09 32763/week @ 2024-11-16 36069/week @ 2024-11-23 45555/week @ 2024-11-30 48321/week @ 2024-12-07 44359/week @ 2024-12-14 26963/week @ 2024-12-21 30182/week @ 2024-12-28 45380/week @ 2025-01-04

155,396 downloads per month
Used in 81 crates (64 directly)

MIT/Apache

195KB
3.5K SLoC

Notify debouncer

» Docs

Tiny debouncer for notify. Filters incoming events and emits only one event per timeframe per file.

Features

  • crossbeam-channel passed down to notify, off by default

  • serde for serde support of event types, off by default

  • serialization-compat-6 passed down to notify, off by default


lib.rs:

Debouncer for notify. Filters incoming events and emits only one event per timeframe per file.

Installation

[dependencies]
notify-debouncer-mini = "0.6.0"

In case you want to select specific features of notify, specify notify as dependency explicitly in your dependencies. Otherwise you can just use the re-export of notify from debouncer-mini.

notify-debouncer-mini = "0.6.0"
notify = { version = "..", features = [".."] }

Examples

See also the full configuration example here.

use notify_debouncer_mini::{notify::*,new_debouncer,DebounceEventResult};

  // Select recommended watcher for debouncer.
  // Using a callback here, could also be a channel.
  let mut debouncer = new_debouncer(Duration::from_secs(2), |res: DebounceEventResult| {
      match res {
          Ok(events) => events.iter().for_each(|e|println!("Event {:?} for {:?}",e.kind,e.path)),
          Err(e) => println!("Error {:?}",e),
      }
  }).unwrap();

  // Add a path to be watched. All files and directories at that path and
  // below will be monitored for changes.
  debouncer.watcher().watch(Path::new("."), RecursiveMode::Recursive).unwrap();

  // note that dropping the debouncer (as will happen here) also ends the debouncer
  // thus this demo would need an endless loop to keep running

Features

The following crate features can be turned on or off in your cargo dependency config:

  • serde passed down to notify-types, off by default
  • crossbeam-channel passed down to notify, off by default
  • macos_fsevent passed down to notify, off by default
  • macos_kqueue passed down to notify, off by default
  • serialization-compat-6 passed down to notify, off by default

Caveats

As all file events are sourced from notify, the known problems section applies here too.

Dependencies

~2–11MB
~131K SLoC