Crate notify[−][src]
Expand description
Cross-platform file system notification library
Installation
[dependencies]
notify = "5.0.0-pre.9"
Serde
Events are serialisable via serde if the serde
feature is enabled:
notify = { version = "5.0.0-pre.9", features = ["serde"] }
Examples
use notify::{Watcher, RecommendedWatcher, RecursiveMode, Result}; fn main() -> Result<()> { // Automatically select the best implementation for your platform. let mut watcher: RecommendedWatcher = Watcher::new_immediate(|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(".", 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: RecommendedWatcher = Watcher::new_immediate(event_fn)?; let mut watcher2: RecommendedWatcher = Watcher::new_immediate(event_fn)?;
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 |
poll | Generic Watcher implementation based on polling |
Structs
Error | Notify error type. |
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
EventFn | The set of requirements for watcher event handling functions. |
Watcher | Type that can deliver file activity notifications |
Functions
immediate_watcher | Convenience method for creating the |
Type Definitions
RecommendedWatcher | The recommended |
Result | Type alias to use this library’s |