#events #notify #watch #notifications #tokio

notify-debouncer-mini

notify mini debouncer for events

9 unstable releases (3 breaking)

0.4.1 Aug 21, 2023
0.4.0 Aug 20, 2023
0.3.0 May 17, 2023
0.2.1 Sep 4, 2022
0.1.3 Aug 17, 2022

#248 in Filesystem

Download history 36156/week @ 2023-12-14 25638/week @ 2023-12-21 30147/week @ 2023-12-28 35498/week @ 2024-01-04 40280/week @ 2024-01-11 43785/week @ 2024-01-18 36494/week @ 2024-01-25 32893/week @ 2024-02-01 34981/week @ 2024-02-08 35937/week @ 2024-02-15 34187/week @ 2024-02-22 36285/week @ 2024-02-29 36096/week @ 2024-03-07 34424/week @ 2024-03-14 37455/week @ 2024-03-21 28146/week @ 2024-03-28

144,059 downloads per month
Used in 56 crates (45 directly)

MIT/Apache

185KB
3K SLoC

Notify debouncer

» Docs

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

Features

  • crossbeam enabled by default, for crossbeam channel support.
    This may create problems used in tokio environments. See #380.
    Use something like the following to disable it.
notify-debouncer-mini = { version = "*", default-features = false }

This also passes through to notify as crossbeam-channel feature.

  • serde for serde support of event types, 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.4.1"

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.4.1"
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:

  • crossbeam enabled by default, adds DebounceEventHandler support for crossbeam channels. Also enables crossbeam-channel in the re-exported notify. You may want to disable this when using the tokio async runtime.
  • serde enables serde support for events.

Caveats

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

Dependencies

~0.5–9.5MB
~63K SLoC