extern crate notify;
use notify::{RecommendedWatcher, Watcher, RecursiveMode};
use std::path::Path;
use std::sync::mpsc::channel;
use std::time::Duration;
fn watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
let (tx, rx) = channel();
let mut watcher: RecommendedWatcher = try!(Watcher::new(tx, Duration::from_secs(2)));
try!(watcher.watch(path, RecursiveMode::Recursive));
loop {
match rx.recv() {
Ok(event) => println!("{:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
}
}
fn main() {
let path = std::env::args().nth(1).expect("Argument 1 needs to be a path");
println!("watching {}", path);
if let Err(e) = watch(path) {
println!("error: {:?}", e)
}
}