| Crates.io | extended-notify |
| lib.rs | extended-notify |
| version | 0.1.0 |
| created_at | 2025-12-10 21:40:52.040721+00 |
| updated_at | 2025-12-10 21:40:52.040721+00 |
| description | extended cross-platform filesystem notifications |
| homepage | https://github.com/estokes/extended-notify |
| repository | https://github.com/estokes/extended-notify |
| max_upload_size | |
| id | 1978827 |
| size | 112,924 |
A filesystem watcher built on notify that adds support for watching paths that don't yet exist, interest-based event filtering, and automatic cleanup via RAII handles.
Watched handle is dropped.EventHandler trait.use extended_notify::{ArcPath, EventBatch, EventHandler, Interest, Watcher};
use anyhow::Result;
use enumflags2::make_bitflags;
struct MyHandler;
impl EventHandler for MyHandler {
async fn handle_event(&mut self, batch: EventBatch) -> Result<()> {
for (id, event) in batch.iter() {
println!("{:?}: {:?}", id, event);
}
Ok(())
}
}
#[tokio::main]
async fn main() -> Result<()> {
let watcher = Watcher::new(MyHandler)?;
// Watch a path that may or may not exist
let interest = make_bitflags!(Interest::{Create | Delete | Modify});
let handle = watcher.add(ArcPath::from("/tmp/watched-file"), interest)?;
// ... do work ...
// Watch stops automatically when handle is dropped
drop(handle);
Ok(())
}
Interests are hierarchical. Subscribing to a parent interest matches all child events:
Delete matches DeleteFile, DeleteFolder, DeleteOtherModify matches all modification types (data, metadata, rename)Any matches everythingSpecial interests:
Established: Synthetic event fired when a watch is first set upAny: Matches all event typesWhen you watch a path:
When a watched path is deleted or renamed away, the watcher automatically transitions back to watching the ancestor and polling. Synthetic Create and Delete events are generated for these transitions if you've subscribed to them.
// Adjust polling interval (default: 1s, minimum: 100ms)
watcher.set_poll_interval(Duration::from_secs(5))?;
// Adjust poll batch size (default: 100, 0 disables polling)
watcher.set_poll_batch(50)?;
MIT