summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2022-08-31 07:52:02 +0200
committerMatthias Beyer <mail@beyermatthias.de>2022-08-31 08:07:02 +0200
commit99bceefee9e9d35bfd993bbd54295be092de2704 (patch)
treed63bc5bed8299f99270bd80c2736d1453531b9ee
parent26c82450084222071464a8fd0bb3d8efde9e73f8 (diff)
Adapt example to new notify interface
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--examples/watch/main.rs19
1 files changed, 15 insertions, 4 deletions
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();