From 4c169bfb9bb5da6449388b9fc90e70932af1388c Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Thu, 6 Jan 2022 19:57:04 -0800 Subject: [PATCH 1/2] Format with `cargo fmt` --- examples/watcher_kind/src/main.rs | 4 ++-- src/fsevent.rs | 6 ++---- src/inotify.rs | 20 +++++++++++++++----- src/lib.rs | 4 +++- src/null.rs | 5 ++++- src/windows.rs | 15 +++++++++------ 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/examples/watcher_kind/src/main.rs b/examples/watcher_kind/src/main.rs index 3f8cdc2c..5324e1e0 100644 --- a/examples/watcher_kind/src/main.rs +++ b/examples/watcher_kind/src/main.rs @@ -4,8 +4,8 @@ use notify::*; fn main() { let (tx, rx) = std::sync::mpsc::channel(); let watcher: Box = if RecommendedWatcher::kind() == WatcherKind::PollWatcher { - Box::new(PollWatcher::with_delay(tx,Duration::from_secs(1)).unwrap()) + Box::new(PollWatcher::with_delay(tx, Duration::from_secs(1)).unwrap()) } else { Box::new(RecommendedWatcher::new(tx).unwrap()) }; -} \ No newline at end of file +} diff --git a/src/fsevent.rs b/src/fsevent.rs index 3232bb0a..00107cdf 100644 --- a/src/fsevent.rs +++ b/src/fsevent.rs @@ -361,10 +361,8 @@ impl FsEventWatcher { cf::CFArrayAppendValue(self.paths, cf_path); cf::CFRelease(cf_path); } - self.recursive_info.insert( - canonical_path, - recursive_mode.is_recursive(), - ); + self.recursive_info + .insert(canonical_path, recursive_mode.is_recursive()); Ok(()) } diff --git a/src/inotify.rs b/src/inotify.rs index 719f45f5..4fcd55af 100644 --- a/src/inotify.rs +++ b/src/inotify.rs @@ -57,7 +57,10 @@ enum EventLoopMsg { } #[inline] -fn send_pending_rename_event(rename_event: &mut Option, event_handler: &mut dyn EventHandler) { +fn send_pending_rename_event( + rename_event: &mut Option, + event_handler: &mut dyn EventHandler, +) { if let Some(e) = rename_event.take() { event_handler.handle_event(Ok(e)); } @@ -492,7 +495,8 @@ impl EventLoop { Error::new(ErrorKind::MaxFilesWatch) } else { Error::io(e) - }.add_path(path)) + } + .add_path(path)) } Ok(w) => { watchmask.remove(WatchMask::MASK_ADD); @@ -512,14 +516,18 @@ impl EventLoop { None => return Err(Error::watch_not_found().add_path(path)), Some((w, _, is_recursive)) => { if let Some(ref mut inotify) = self.inotify { - inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(path.clone()))?; + inotify + .rm_watch(w.clone()) + .map_err(|e| Error::io(e).add_path(path.clone()))?; self.paths.remove(&w); if is_recursive || remove_recursive { let mut remove_list = Vec::new(); for (w, p) in &self.paths { if p.starts_with(&path) { - inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(p.into()))?; + inotify + .rm_watch(w.clone()) + .map_err(|e| Error::io(e).add_path(p.into()))?; self.watches.remove(p); remove_list.push(w.clone()); } @@ -537,7 +545,9 @@ impl EventLoop { fn remove_all_watches(&mut self) -> Result<()> { if let Some(ref mut inotify) = self.inotify { for (w, p) in &self.paths { - inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(p.into()))?; + inotify + .rm_watch(w.clone()) + .map_err(|e| Error::io(e).add_path(p.into()))?; } self.watches.clear(); self.paths.clear(); diff --git a/src/lib.rs b/src/lib.rs index a9c6646e..7722f372 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,7 +252,9 @@ pub trait Watcher { } /// Returns the watcher kind, allowing to perform backend-specific tasks - fn kind() -> WatcherKind where Self: Sized; + fn kind() -> WatcherKind + where + Self: Sized; } /// The recommended `Watcher` implementation for the current platform diff --git a/src/null.rs b/src/null.rs index 3d2e5894..27daa526 100644 --- a/src/null.rs +++ b/src/null.rs @@ -20,7 +20,10 @@ impl Watcher for NullWatcher { Ok(()) } - fn new(event_handler: F) -> Result where Self: Sized { + fn new(event_handler: F) -> Result + where + Self: Sized, + { Ok(NullWatcher) } diff --git a/src/windows.rs b/src/windows.rs index 566ed687..e015f79f 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -15,7 +15,7 @@ use winapi::um::synchapi; use winapi::um::winbase::{self, INFINITE, WAIT_OBJECT_0}; use winapi::um::winnt::{self, FILE_NOTIFY_INFORMATION, HANDLE}; -use crate::{WatcherKind, event::*}; +use crate::{event::*, WatcherKind}; use crate::{Config, Error, EventHandler, RecursiveMode, Result, Watcher}; use crossbeam_channel::{bounded, unbounded, Receiver, Sender}; use std::collections::HashMap; @@ -146,9 +146,10 @@ impl ReadDirectoryChangesServer { fn add_watch(&mut self, path: PathBuf, is_recursive: bool) -> Result { // path must exist and be either a file or directory if !path.is_dir() && !path.is_file() { - return Err(Error::generic( - "Input watch path is neither a file nor a directory.", - ).add_path(path)); + return Err( + Error::generic("Input watch path is neither a file nor a directory.") + .add_path(path), + ); } let (watching_file, dir_target) = { @@ -182,7 +183,8 @@ impl ReadDirectoryChangesServer { Error::generic( "You attempted to watch a single file, but parent \ directory could not be opened.", - ).add_path(path) + ) + .add_path(path) } else { // TODO: Call GetLastError for better error info? Error::path_not_found().add_path(path) @@ -416,7 +418,8 @@ impl ReadDirectoryChangesWatcher { return Err(Error::generic("Failed to create wakeup semaphore.")); } - let action_tx = ReadDirectoryChangesServer::start(event_handler, meta_tx, cmd_tx, wakeup_sem); + let action_tx = + ReadDirectoryChangesServer::start(event_handler, meta_tx, cmd_tx, wakeup_sem); Ok(ReadDirectoryChangesWatcher { tx: action_tx, From cbd0dd5d8b0076291467ed40878b9d1b5b36e657 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Thu, 6 Jan 2022 19:58:09 -0800 Subject: [PATCH 2/2] Avoid cloning Copy types Found via `cargo clippy` --- src/event.rs | 2 +- tests/serialise-events.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event.rs b/src/event.rs index 84b7de0a..6f2620da 100644 --- a/src/event.rs +++ b/src/event.rs @@ -426,7 +426,7 @@ impl EventAttributes { /// Retrieves the Notify flag for an event directly, if present. pub fn flag(&self) -> Option { - self.inner.as_ref().and_then(|inner| inner.flag.clone()) + self.inner.as_ref().and_then(|inner| inner.flag) } /// Retrieves the additional info for an event directly, if present. diff --git a/tests/serialise-events.rs b/tests/serialise-events.rs index bc2c986e..6f4952e7 100644 --- a/tests/serialise-events.rs +++ b/tests/serialise-events.rs @@ -18,7 +18,7 @@ fn events_are_debuggable() { ); let mut attrs = EventAttributes::new(); - attrs.set_info("unmount".into()); + attrs.set_info("unmount"); attrs.set_flag(Flag::Rescan); assert_eq!(