|
1 | 1 | #![allow(deprecated)]
|
2 | 2 | use config::{Config, File};
|
3 |
| -use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; |
| 3 | +use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher}; |
4 | 4 | use std::collections::HashMap;
|
| 5 | +use std::path::Path; |
5 | 6 | use std::sync::mpsc::channel;
|
6 | 7 | use std::sync::RwLock;
|
7 | 8 | use std::time::Duration;
|
@@ -33,19 +34,29 @@ fn watch() {
|
33 | 34 |
|
34 | 35 | // Automatically select the best implementation for your platform.
|
35 | 36 | // You can also access each implementation directly e.g. INotifyWatcher.
|
36 |
| - let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2)).unwrap(); |
| 37 | + let mut watcher: RecommendedWatcher = Watcher::new( |
| 38 | + tx, |
| 39 | + notify::Config::default().with_poll_interval(Duration::from_secs(2)), |
| 40 | + ) |
| 41 | + .unwrap(); |
37 | 42 |
|
38 | 43 | // Add a path to be watched. All files and directories at that path and
|
39 | 44 | // below will be monitored for changes.
|
40 | 45 | watcher
|
41 |
| - .watch("examples/watch/Settings.toml", RecursiveMode::NonRecursive) |
| 46 | + .watch( |
| 47 | + Path::new("examples/watch/Settings.toml"), |
| 48 | + RecursiveMode::NonRecursive, |
| 49 | + ) |
42 | 50 | .unwrap();
|
43 | 51 |
|
44 | 52 | // This is a simple loop, but you may want to use more complex logic here,
|
45 | 53 | // for example to handle I/O.
|
46 | 54 | loop {
|
47 | 55 | match rx.recv() {
|
48 |
| - Ok(DebouncedEvent::Write(_)) => { |
| 56 | + Ok(Ok(Event { |
| 57 | + kind: notify::event::EventKind::Modify(_), |
| 58 | + .. |
| 59 | + })) => { |
49 | 60 | println!(" * Settings.toml written; refreshing configuration ...");
|
50 | 61 | SETTINGS.write().unwrap().refresh().unwrap();
|
51 | 62 | show();
|
|
0 commit comments