#notify #events #watch

notify-win-debouncer-mini

notify-win mini debouncer for events

2 releases

new 0.1.2 Dec 28, 2024
0.1.0 Dec 28, 2024

#1422 in Filesystem

MIT/Apache

120KB
2K SLoC

Notify Win Debouncer

» Docs

Tiny debouncer for notify-win. 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-win-debouncer-mini = "0.1.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-win-debouncer-mini = "0.1.0"
notify-win = { version = "..", features = [".."] }
use notify_win_debouncer_mini::{notify_win::*,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-channel passed down to notify, off by default
  • serde enables serde support for events, off by default
  • serialization-compat-6 passed down to notify, off by default

Dependencies

~11–20MB
~294K SLoC