forked from notify-rs/notify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatcher_kind.rs
28 lines (25 loc) · 1.01 KB
/
watcher_kind.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use notify::*;
use std::{path::Path, time::Duration};
// example of detecting the recommended watcher kind
fn main() {
let (tx, rx) = std::sync::mpsc::channel();
// This example is a little bit misleading as you can just create one Config and use it for all watchers.
// That way the pollwatcher specific stuff is still configured, if it should be used.
let mut watcher: Box<dyn Watcher> = if RecommendedWatcher::kind() == WatcherKind::PollWatcher {
// custom config for PollWatcher kind
// you
let config = Config::default().with_poll_interval(Duration::from_secs(1));
Box::new(PollWatcher::new(tx, config).unwrap())
} else {
// use default config for everything else
Box::new(RecommendedWatcher::new(tx, Config::default()).unwrap())
};
// watch some stuff
watcher
.watch(Path::new("."), RecursiveMode::Recursive)
.unwrap();
// just print all events, this blocks forever
for e in rx {
println!("{:?}", e);
}
}