diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2022-08-31 08:12:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 08:12:13 +0200 |
commit | d655c66ff41b75b6cc20a9176d5f1ef4268deece (patch) | |
tree | d63bc5bed8299f99270bd80c2736d1453531b9ee | |
parent | eb32915b32591557a3a253be5bd9464d49d8518c (diff) | |
parent | 99bceefee9e9d35bfd993bbd54295be092de2704 (diff) |
Merge pull request #373 from matthiasbeyer/update-notify
Update notify
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | examples/watch/main.rs | 19 |
2 files changed, 16 insertions, 5 deletions
@@ -49,5 +49,5 @@ reqwest = "0.11.10" serde = "1.0" glob = "0.3" lazy_static = "1" -notify = "^4.0.0" +notify = "^5.0.0" temp-env = "0.2.0" diff --git a/examples/watch/main.rs b/examples/watch/main.rs index 801ee4f..ca83572 100644 --- a/examples/watch/main.rs +++ b/examples/watch/main.rs @@ -1,7 +1,8 @@ #![allow(deprecated)] use config::{Config, File}; -use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; +use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher}; use std::collections::HashMap; +use std::path::Path; use std::sync::mpsc::channel; use std::sync::RwLock; use std::time::Duration; @@ -33,19 +34,29 @@ fn watch() { // Automatically select the best implementation for your platform. // You can also access each implementation directly e.g. INotifyWatcher. - let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2)).unwrap(); + let mut watcher: RecommendedWatcher = Watcher::new( + tx, + notify::Config::default().with_poll_interval(Duration::from_secs(2)), + ) + .unwrap(); // Add a path to be watched. All files and directories at that path and // below will be monitored for changes. watcher - .watch("examples/watch/Settings.toml", RecursiveMode::NonRecursive) + .watch( + Path::new("examples/watch/Settings.toml"), + RecursiveMode::NonRecursive, + ) .unwrap(); // This is a simple loop, but you may want to use more complex logic here, // for example to handle I/O. loop { match rx.recv() { - Ok(DebouncedEvent::Write(_)) => { + Ok(Ok(Event { + kind: notify::event::EventKind::Modify(_), + .. + })) => { println!(" * Settings.toml written; refreshing configuration ..."); SETTINGS.write().unwrap().refresh().unwrap(); show(); |