I'm trying to implement a filesystem watcher in Rust. I can receive events when filesystem objects have changed but determining what change was made has me stumped. I found code on the latest released version of the Notify package here that takes me almost the whole way there.
How can I extract the path and type out of the event? The event is an enumerated type, yet somehow when it's printed, I see all the info I want.
I am obviously missing something very fundamental.
use notify::{watcher, RecursiveMode, Watcher};
use std::sync::mpsc::channel;
use std::time::Duration;
fn main() {
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(10)).unwrap();
watcher
.watch("/tmp/path", RecursiveMode::Recursive)
.unwrap();
loop {
match rx.recv() {
Ok(event) => {
// **>> event.filename? event.type? how?
println!("{:?}", event);
}
Err(e) => println!("watch error: {:?}", e),
}
}
}