Skip to content

Commit

Permalink
Format and fix clippy warning (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmfink committed Jan 8, 2022
1 parent 704e6d6 commit 0697fae
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/watcher_kind/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use notify::*;
fn main() {
let (tx, rx) = std::sync::mpsc::channel();
let watcher: Box<dyn Watcher> = 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())
};
}
}
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl EventAttributes {

/// Retrieves the Notify flag for an event directly, if present.
pub fn flag(&self) -> Option<Flag> {
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.
Expand Down
6 changes: 2 additions & 4 deletions src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
20 changes: 15 additions & 5 deletions src/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ enum EventLoopMsg {
}

#[inline]
fn send_pending_rename_event(rename_event: &mut Option<Event>, event_handler: &mut dyn EventHandler) {
fn send_pending_rename_event(
rename_event: &mut Option<Event>,
event_handler: &mut dyn EventHandler,
) {
if let Some(e) = rename_event.take() {
event_handler.handle_event(Ok(e));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand All @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ impl Watcher for NullWatcher {
Ok(())
}

fn new<F: crate::EventHandler>(event_handler: F) -> Result<Self> where Self: Sized {
fn new<F: crate::EventHandler>(event_handler: F) -> Result<Self>
where
Self: Sized,
{
Ok(NullWatcher)
}

Expand Down
15 changes: 9 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,9 +146,10 @@ impl ReadDirectoryChangesServer {
fn add_watch(&mut self, path: PathBuf, is_recursive: bool) -> Result<PathBuf> {
// 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) = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/serialise-events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 0697fae

Please sign in to comment.