Crate notify_debouncer_full
source ·Expand description
A debouncer for notify that is optimized for ease of use.
- Only emits a single
Rename
event if the renameFrom
andTo
events can be matched - Merges multiple
Rename
events - Takes
Rename
events into account and updates paths for events that occurred before the rename event, but which haven’t been emitted, yet - Optionally keeps track of the file system IDs all files and stiches rename events together (FSevents, Windows)
- Emits only one
Remove
event when deleting a directory (inotify) - Doesn’t emit duplicate create events
- Doesn’t emit
Modify
events after aCreate
event
Installation
[dependencies]
notify-debouncer-full = "0.2.0"
In case you want to select specific features of notify, specify notify as dependency explicitely in your dependencies. Otherwise you can just use the re-export of notify from debouncer-full.
notify-debouncer-full = "0.2.0"
notify = { version = "..", features = [".."] }
Examples
use notify_debouncer_full::{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), None, |result: DebounceEventResult| {
match result {
Ok(events) => events.iter().for_each(|event| println!("{event:?}")),
Err(errors) => errors.iter().for_each(|error| println!("{error:?}")),
}
}).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();
// Add the same path to the file ID cache. The cache uses unique file IDs
// provided by the file system and is used to stich together rename events
// in case the notification back-end doesn't emit rename cookies.
debouncer.cache().add_root(Path::new("."), RecursiveMode::Recursive);
Features
The following crate features can be turned on or off in your cargo dependency config:
crossbeam
enabled by default, addsDebounceEventHandler
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.
Re-exports
Structs
- A debounced event is emitted after a short delay.
- Debouncer guard, stops the debouncer on drop.
- A cache to hold the file system IDs of all watched files.
- An implementation of the
FileIdCache
trait that doesn’t hold any data.
Traits
- The set of requirements for watcher debounce event handling functions.
- The interface of a file ID cache.
Functions
- Short function to create a new debounced watcher with the recommended debouncer and the built-in file ID cache.
- Creates a new debounced watcher with custom configuration.
Type Definitions
- A result of debounced events. Comes with either a vec of events or vec of errors.