-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathmultiple_backends.rs
39 lines (35 loc) · 1.29 KB
/
multiple_backends.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
29
30
31
32
33
34
35
36
37
38
39
use notify::{RecursiveMode, Result, Watcher, Config};
use std::path::Path;
fn direct_init() -> Result<()> {
fn event_fn(res: Result<notify::Event>) {
match res {
Ok(event) => println!("event: {:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
}
let mut watcher1 = notify::recommended_watcher(event_fn)?;
// we will just use the same watcher kind again here
let mut watcher2 = notify::recommended_watcher(event_fn)?;
watcher1.watch(Path::new("."), RecursiveMode::Recursive)?;
watcher2.watch(Path::new("."), RecursiveMode::Recursive)?;
Ok(())
}
fn fallback_init() -> Result<()> {
fn event_fn(res: Result<notify::Event>) {
match res {
Ok(event) => println!("event: {:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
}
let mut watcher1 = notify::recommended_watcher_fallback(event_fn, Config::default())?;
// we will just use the same watcher kind again here
let mut watcher2 = notify::recommended_watcher_fallback(event_fn, Config::default())?;
watcher1.watch(Path::new("."), RecursiveMode::Recursive)?;
watcher2.watch(Path::new("."), RecursiveMode::Recursive)?;
Ok(())
}
fn main() -> Result<()> {
direct_init()?;
fallback_init()?;
Ok(())
}