Expand description
Cross-platform file system notification library
Installation
[dependencies]
notify = "5.0.0-pre.14"
Serde
Events are serialisable via serde if the serde
feature is enabled:
notify = { version = "5.0.0-pre.14", features = ["serde"] }
Examples
use notify::{Watcher, RecommendedWatcher, RecursiveMode, Result};
fn main() -> Result<()> {
// Automatically select the best implementation for your platform.
let mut watcher = notify::recommended_watcher(|res| {
match res {
Ok(event) => println!("event: {:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
})?;
// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
watcher.watch(Path::new("."), RecursiveMode::Recursive)?;
Ok(())
}
With precise events
By default, Notify emits non-descript events containing only the affected path and some
metadata. To get richer details about what the events are about, you need to enable
Config::PreciseEvents
. The full event
classification is described in the event
module documentation.
use notify::Config;
watcher.configure(Config::PreciseEvents(true))?;
With different configurations
It is possible to create several watchers with different configurations or implementations that all call the same event function. This can accommodate advanced behaviour or work around limits.
fn event_fn(res: Result<notify::Event>) {
match res {
Ok(event) => println!("event: {:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
}
let mut watcher1 = notify::recommended_watcher(event_fn)?;
let mut watcher2 = notify::recommended_watcher(event_fn)?;
Re-exports
pub use event::Event;
pub use event::EventKind;
pub use null::NullWatcher;
pub use poll::PollWatcher;
pub use windows::ReadDirectoryChangesWatcher;
Modules
The Event
type and the hierarchical EventKind
descriptor.
Stub Watcher implementation
Generic Watcher implementation based on polling
Watcher implementation for Windows’ directory management APIs
Structs
Notify error type.
Enums
Runtime configuration items for watchers.
Error kinds
Indicates whether only the provided directory or its sub-directories as well should be watched
Watcher kind enumeration
Traits
The set of requirements for watcher event handling functions.
Type that can deliver file activity notifications
Functions
Convenience method for creating the RecommendedWatcher
for the current platform in
immediate mode.
Type Definitions
The recommended Watcher
implementation for the current platform
Type alias to use this library’s Error
type in a Result