From f40e734a6a8b46aa30318b102a059e6fa09a083a Mon Sep 17 00:00:00 2001 From: coswat Date: Sat, 30 Sep 2023 19:57:36 +0530 Subject: [PATCH 1/3] applied changes recommended by clippy --- notify/src/error.rs | 2 +- notify/src/inotify.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/notify/src/error.rs b/notify/src/error.rs index b7feb8be..7bed4fed 100644 --- a/notify/src/error.rs +++ b/notify/src/error.rs @@ -93,7 +93,7 @@ impl Error { /// Creates a new "invalid config" error from the given `Config`. pub fn invalid_config(config: &Config) -> Self { - Self::new(ErrorKind::InvalidConfig(config.clone())) + Self::new(ErrorKind::InvalidConfig(*config)) } } diff --git a/notify/src/inotify.rs b/notify/src/inotify.rs index e5aca45f..ccf8187f 100644 --- a/notify/src/inotify.rs +++ b/notify/src/inotify.rs @@ -211,9 +211,7 @@ impl EventLoop { } let path = match event.name { - Some(name) => { - self.paths.get(&event.wd).map(|root| root.join(&name)) - } + Some(name) => self.paths.get(&event.wd).map(|root| root.join(name)), None => self.paths.get(&event.wd).cloned(), }; From c930a8c0b709382256350194680e456eb3f35150 Mon Sep 17 00:00:00 2001 From: coswat Date: Sat, 30 Sep 2023 20:01:39 +0530 Subject: [PATCH 2/3] removed unused import from debouncer_mini.rs --- examples/debouncer_mini.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/debouncer_mini.rs b/examples/debouncer_mini.rs index 3f613f93..2ac5540c 100644 --- a/examples/debouncer_mini.rs +++ b/examples/debouncer_mini.rs @@ -1,11 +1,14 @@ -use std::{io::Write, path::Path, time::Duration}; +use std::{path::Path, time::Duration}; use notify::RecursiveMode; use notify_debouncer_mini::new_debouncer; /// Example for debouncer mini fn main() { - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debouncer_mini=trace")).init(); + env_logger::Builder::from_env( + env_logger::Env::default().default_filter_or("debouncer_mini=trace"), + ) + .init(); // emit some events by changing a file std::thread::spawn(|| { let path = Path::new("test.txt"); @@ -40,7 +43,9 @@ fn main() { // print all events, non returning for result in rx { match result { - Ok(events) => events.iter().for_each(|event| log::info!("Event {event:?}")), + Ok(events) => events + .iter() + .for_each(|event| log::info!("Event {event:?}")), Err(error) => log::info!("Error {error:?}"), } } From 3b0a748987a86900f9a9bc8c04ecb8299c28da9d Mon Sep 17 00:00:00 2001 From: coswat Date: Sat, 30 Sep 2023 20:02:17 +0530 Subject: [PATCH 3/3] code format by cargo fmt --- examples/debouncer_mini_custom.rs | 10 ++++------ examples/pollwatcher_manual.rs | 17 ++++++++--------- notify-debouncer-full/src/lib.rs | 4 ++-- notify-debouncer-mini/src/lib.rs | 6 +++--- notify/src/config.rs | 6 +++--- notify/src/lib.rs | 10 +++++----- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/examples/debouncer_mini_custom.rs b/examples/debouncer_mini_custom.rs index 91715c3e..c5654a5f 100644 --- a/examples/debouncer_mini_custom.rs +++ b/examples/debouncer_mini_custom.rs @@ -20,13 +20,11 @@ fn main() { // notify backend configuration let backend_config = notify::Config::default().with_poll_interval(Duration::from_secs(1)); // debouncer configuration - let debouncer_config = Config::default().with_timeout(Duration::from_millis(1000)).with_notify_config(backend_config); + let debouncer_config = Config::default() + .with_timeout(Duration::from_millis(1000)) + .with_notify_config(backend_config); // select backend via fish operator, here PollWatcher backend - let mut debouncer = new_debouncer_opt::<_, notify::PollWatcher>( - debouncer_config, - tx, - ) - .unwrap(); + let mut debouncer = new_debouncer_opt::<_, notify::PollWatcher>(debouncer_config, tx).unwrap(); debouncer .watcher() diff --git a/examples/pollwatcher_manual.rs b/examples/pollwatcher_manual.rs index 3fc0f61b..bb440fdd 100644 --- a/examples/pollwatcher_manual.rs +++ b/examples/pollwatcher_manual.rs @@ -20,22 +20,21 @@ fn main() { fn watch>(path: P) -> notify::Result<()> { let (tx, rx) = std::sync::mpsc::channel(); // use the PollWatcher and disable automatic polling - let mut watcher = PollWatcher::new( - tx, - Config::default().with_manual_polling(), - )?; + let mut watcher = PollWatcher::new(tx, Config::default().with_manual_polling())?; // Add a path to be watched. All files and directories at that path and // below will be monitored for changes. watcher.watch(path.as_ref(), RecursiveMode::Recursive)?; // run event receiver on a different thread, we want this one for user input - std::thread::spawn(move ||{for res in rx { - match res { - Ok(event) => println!("changed: {:?}", event), - Err(e) => println!("watch error: {:?}", e), + std::thread::spawn(move || { + for res in rx { + match res { + Ok(event) => println!("changed: {:?}", event), + Err(e) => println!("watch error: {:?}", e), + } } - }}); + }); // wait for any input and poll loop { diff --git a/notify-debouncer-full/src/lib.rs b/notify-debouncer-full/src/lib.rs index 7d2595d5..598ed23a 100644 --- a/notify-debouncer-full/src/lib.rs +++ b/notify-debouncer-full/src/lib.rs @@ -57,9 +57,9 @@ //! - `crossbeam` enabled by default, adds [`DebounceEventHandler`](DebounceEventHandler) support for crossbeam channels. //! Also enables crossbeam-channel in the re-exported notify. You may want to disable this when using the tokio async runtime. //! - `serde` enables serde support for events. -//! +//! //! # Caveats -//! +//! //! As all file events are sourced from notify, the [known problems](https://docs.rs/notify/latest/notify/#known-problems) section applies here too. mod cache; diff --git a/notify-debouncer-mini/src/lib.rs b/notify-debouncer-mini/src/lib.rs index 4bcd9a3c..8965b047 100644 --- a/notify-debouncer-mini/src/lib.rs +++ b/notify-debouncer-mini/src/lib.rs @@ -35,7 +35,7 @@ //! // Add a path to be watched. All files and directories at that path and //! // below will be monitored for changes. //! debouncer.watcher().watch(Path::new("."), RecursiveMode::Recursive).unwrap(); -//! +//! //! // note that dropping the debouncer (as will happen here) also ends the debouncer //! // thus this demo would need an endless loop to keep running //! # } @@ -48,9 +48,9 @@ //! - `crossbeam` enabled by default, adds [`DebounceEventHandler`](DebounceEventHandler) support for crossbeam channels. //! Also enables crossbeam-channel in the re-exported notify. You may want to disable this when using the tokio async runtime. //! - `serde` enables serde support for events. -//! +//! //! # Caveats -//! +//! //! As all file events are sourced from notify, the [known problems](https://docs.rs/notify/latest/notify/#known-problems) section applies here too. #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/notify/src/config.rs b/notify/src/config.rs index c3c66ff5..7c0b59e0 100644 --- a/notify/src/config.rs +++ b/notify/src/config.rs @@ -51,7 +51,7 @@ impl Config { /// file trees so it is recommended to measure and tune accordingly. /// /// The default poll frequency is 30 seconds. - /// + /// /// This will enable automatic polling, overwriting [with_manual_polling](Config::with_manual_polling). pub fn with_poll_interval(mut self, dur: Duration) -> Self { // TODO: v7.0 break signature to option @@ -76,9 +76,9 @@ impl Config { } /// For the [PollWatcher](crate::PollWatcher) backend. - /// + /// /// Disable automatic polling. Requires calling [crate::PollWatcher::poll] manually. - /// + /// /// This will disable automatic polling, overwriting [with_poll_interval](Config::with_poll_interval). pub fn with_manual_polling(mut self) -> Self { self.poll_interval = None; diff --git a/notify/src/lib.rs b/notify/src/lib.rs index 3ee98b8e..f5efaa71 100644 --- a/notify/src/lib.rs +++ b/notify/src/lib.rs @@ -41,12 +41,12 @@ //! Note the `macos_kqueue` requirement here, otherwise no native backend is available on macos. //! //! # Known Problems -//! +//! //! ### Network filesystems -//! +//! //! Network mounted filesystems like NFS may not emit any events for notify to listen to. //! This applies especially to WSL programs watching windows paths ([issue #254](https://github.com/notify-rs/notify/issues/254)). -//! +//! //! A workaround is the [PollWatcher] backend. //! //! ### Docker with Linux on MacOS M1 @@ -92,10 +92,10 @@ //! Note that the [PollWatcher] is not restricted by this limitation, so it may be an alternative if your users can't increase the limit. //! //! ### Watching large directories -//! +//! //! When watching a very large amount of files, notify may fail to receive all events. //! For example the linux backend is documented to not be a 100% reliable source. See also issue [#412](https://github.com/notify-rs/notify/issues/412). -//! +//! //! # Examples //! //! For more examples visit the [examples folder](https://github.com/notify-rs/notify/tree/main/examples) in the repository.