[−][src]Crate notify
Cross-platform file system notification library
Installation
[dependencies]
notify = "=5.0.0-pre.1"
Serde
Debounced Events are serialisable via serde if the serde
feature is enabled:
notify = { version = "=5.0.0-pre.1", features = ["serde"] }
Examples
extern crate crossbeam_channel; extern crate notify; use crossbeam_channel::unbounded; use notify::{RecommendedWatcher, RecursiveMode, Result, Watcher}; use std::time::Duration; fn main() -> Result<()> { // Create a channel to receive the events. let (tx, rx) = unbounded(); // Automatically select the best implementation for your platform. let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?; // Add a path to be watched. All files and directories at that path and // below will be monitored for changes. watcher.watch(".", RecursiveMode::Recursive)?; loop { match rx.recv() { Ok(event) => println!("changed: {:?}", event), Err(err) => println!("watch error: {:?}", err), }; } Ok(()) }
Without debouncing
To receive events as they are emitted, without debouncing at all:
let mut watcher: RecommendedWatcher = Watcher::new_immediate(tx)?;
With different configurations
It is possible to create several watchers with different configurations or implementations that all send to the same channel. This can accommodate advanced behaviour or work around limits.
let mut watcher1: RecommendedWatcher = Watcher::new_immediate(tx.clone())?; let mut watcher2: RecommendedWatcher = Watcher::new_immediate(tx)?; loop { match rx.recv() { Ok(event) => println!("event: {:?}", event), Err(e) => println!("watch error: {:?}", e), } }
Re-exports
pub use event::Event; |
pub use event::EventKind; |
pub use crate::inotify::INotifyWatcher; |
pub use null::NullWatcher; |
pub use poll::PollWatcher; |
Modules
event | The |
inotify | Watcher implementation for the inotify Linux API |
null | Stub Watcher implementation |
op | |
poll | Generic Watcher implementation based on polling |
Structs
Error | Notify error type. |
Op | |
RawEvent |
Enums
Config | Runtime configuration items for watchers. |
ErrorKind | Error kinds |
RecursiveMode | Indicates whether only the provided directory or its sub-directories as well should be watched |
Traits
Watcher | Type that can deliver file activity notifications |
Functions
immediate_watcher | Convenience method for creating the |
watcher | Convenience method for creating the |
Type Definitions
RecommendedWatcher | The recommended |
Result | Type alias to use this library's |