From a3c5bd72013eab88f4b4080f6feac732e822e3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Mon, 28 Oct 2019 00:31:52 +1300 Subject: [PATCH] Run formatter --- src/cli.rs | 14 ++++++++------ src/error.rs | 7 ++++--- src/gitignore.rs | 29 +++++++++++++++++------------ src/ignore.rs | 16 +++++++++++----- src/notification_filter.rs | 2 +- src/process.rs | 29 ++++++++++++++--------------- src/run.rs | 2 +- src/signal.rs | 4 ++-- 8 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3807dbe..0520cca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,8 +14,8 @@ //! .unwrap(); //! ``` -use clap::{App, Arg, Error}; use crate::error; +use clap::{App, Arg, Error}; use std::{ ffi::OsString, path::{PathBuf, MAIN_SEPARATOR}, @@ -216,11 +216,13 @@ where if let Some(extensions) = args.values_of("extensions") { for exts in extensions { - filters.extend( - exts.split(',') - .filter_map(|ext| if ext.is_empty() { None } else { - Some(format!("*.{}", ext.replace(".", ""))) }), - ); + filters.extend(exts.split(',').filter_map(|ext| { + if ext.is_empty() { + None + } else { + Some(format!("*.{}", ext.replace(".", ""))) + } + })); } } diff --git a/src/error.rs b/src/error.rs index 36c7ade..9a140e4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -55,9 +55,10 @@ impl<'a, T> From> for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (error_type, error) = match self { - Self::Canonicalization(path, err) => { - ("Path", format!("couldn't canonicalize '{}':\n{}", path, err)) - } + Self::Canonicalization(path, err) => ( + "Path", + format!("couldn't canonicalize '{}':\n{}", path, err), + ), Self::Clap(err) => ("Argument", err.to_string()), Self::Glob(err) => ("Globset", err.to_string()), Self::Io(err) => ("I/O", err.to_string()), diff --git a/src/gitignore.rs b/src/gitignore.rs index 6288d01..d9b2b99 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -55,9 +55,9 @@ pub fn load(paths: &[PathBuf]) -> Gitignore { let gitignore_path = p.join(".gitignore"); if gitignore_path.exists() { if let Ok(f) = GitignoreFile::new(&gitignore_path) { - debug!("Loaded {:?}", gitignore_path); - files.push(f); - } else { + debug!("Loaded {:?}", gitignore_path); + files.push(f); + } else { debug!("Unable to load {:?}", gitignore_path); } } @@ -82,8 +82,8 @@ pub fn load(paths: &[PathBuf]) -> Gitignore { } impl Gitignore { - const fn new(files: Vec) -> Self{ - Self{ files } + const fn new(files: Vec) -> Self { + Self { files } } pub fn is_excluded(&self, path: &Path) -> bool { @@ -143,7 +143,7 @@ impl GitignoreFile { patterns.push(p); } - Ok(Self{ + Ok(Self { set: builder.build()?, patterns, root: root.to_owned(), @@ -181,14 +181,19 @@ impl GitignoreFile { fn parse(contents: &[&str]) -> Vec { contents .iter() - .filter_map(|l| if !l.is_empty() && !l.starts_with('#') { - Some(Pattern::parse(l)) } else { None }) + .filter_map(|l| { + if !l.is_empty() && !l.starts_with('#') { + Some(Pattern::parse(l)) + } else { + None + } + }) .collect() } } impl Pattern { - fn parse(pattern: &str) -> Self{ + fn parse(pattern: &str) -> Self { let mut normalized = String::from(pattern); let pattern_type = if normalized.starts_with('!') { @@ -213,7 +218,7 @@ impl Pattern { normalized.remove(0); } - Self{ + Self { pattern: normalized, pattern_type, anchored, @@ -222,13 +227,13 @@ impl Pattern { } impl From for Error { - fn from(error: globset::Error) -> Self{ + fn from(error: globset::Error) -> Self { Self::GlobSet(error) } } impl From for Error { - fn from(error: io::Error) -> Self{ + fn from(error: io::Error) -> Self { Self::Io(error) } } diff --git a/src/ignore.rs b/src/ignore.rs index cd3493f..bf38e02 100644 --- a/src/ignore.rs +++ b/src/ignore.rs @@ -55,10 +55,10 @@ pub fn load(paths: &[PathBuf]) -> Ignore { let ignore_path = p.join(".ignore"); if ignore_path.exists() { if let Ok(f) = IgnoreFile::new(&ignore_path) { - debug!("Loaded {:?}", ignore_path); - files.push(f); - } else { - debug!("Unable to load {:?}", ignore_path); + debug!("Loaded {:?}", ignore_path); + files.push(f); + } else { + debug!("Unable to load {:?}", ignore_path); } } } @@ -174,7 +174,13 @@ impl IgnoreFile { fn parse(contents: &[&str]) -> Vec { contents .iter() - .filter_map(|l| if !l.is_empty() && !l.starts_with('#') { Some(Pattern::parse(l)) } else { None }) + .filter_map(|l| { + if !l.is_empty() && !l.starts_with('#') { + Some(Pattern::parse(l)) + } else { + None + } + }) .collect() } } diff --git a/src/notification_filter.rs b/src/notification_filter.rs index 39f40ad..95220ad 100644 --- a/src/notification_filter.rs +++ b/src/notification_filter.rs @@ -1,7 +1,7 @@ use crate::error; use crate::gitignore::Gitignore; -use globset::{Glob, GlobSet, GlobSetBuilder}; use crate::ignore::Ignore; +use globset::{Glob, GlobSet, GlobSetBuilder}; use std::path::Path; pub struct NotificationFilter { diff --git a/src/process.rs b/src/process.rs index de3b04f..92321fb 100644 --- a/src/process.rs +++ b/src/process.rs @@ -59,10 +59,10 @@ fn wrap_commands(cmd: &Vec) -> Vec { #[cfg(target_family = "unix")] mod imp { //use super::wrap_commands; - use nix::libc::*; - use nix::{self, Error}; use crate::pathop::PathOp; use crate::signal::Signal; + use nix::libc::*; + use nix::{self, Error}; use std::io::{self, Result}; use std::process::Command; use std::sync::*; @@ -85,8 +85,8 @@ mod imp { impl Process { pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result { use nix::unistd::*; + use std::convert::TryInto; use std::os::unix::process::CommandExt; - use std::convert::TryInto; // Assemble command to run. // This is either the first argument from cmd (if no_shell was given) or "sh". @@ -112,16 +112,16 @@ mod imp { command.env(name, val); } - unsafe { command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ())); } - command - .spawn() - .and_then(|p| { - Ok(Self { - pgid: p.id().try_into().unwrap(), - lock: Mutex::new(false), - cvar: Condvar::new(), - }) + unsafe { + command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ())); + } + command.spawn().and_then(|p| { + Ok(Self { + pgid: p.id().try_into().unwrap(), + lock: Mutex::new(false), + cvar: Condvar::new(), }) + }) } pub fn reap(&self) { @@ -131,8 +131,7 @@ mod imp { let mut finished = true; loop { match waitpid(Pid::from_raw(-self.pgid), Some(WaitPidFlag::WNOHANG)) { - Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => { - } + Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {} Ok(_) => { finished = false; break; @@ -178,9 +177,9 @@ mod imp { #[cfg(target_family = "windows")] mod imp { //use super::wrap_commands; - use kernel32::*; use crate::pathop::PathOp; use crate::signal::Signal; + use kernel32::*; use std::io; use std::io::Result; use std::mem; diff --git a/src/run.rs b/src/run.rs index 9078d78..812ae01 100644 --- a/src/run.rs +++ b/src/run.rs @@ -6,6 +6,7 @@ use crate::notification_filter::NotificationFilter; use crate::pathop::PathOp; use crate::process::{self, Process}; use crate::signal::{self, Signal}; +use crate::watcher::{Event, Watcher}; use std::{ collections::HashMap, fs::canonicalize, @@ -16,7 +17,6 @@ use std::{ }, time::Duration, }; -use crate::watcher::{Event, Watcher}; fn init_logger(debug: bool) { let mut log_builder = env_logger::Builder::new(); diff --git a/src/signal.rs b/src/signal.rs index efa3edc..550fb14 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -100,7 +100,7 @@ where set_handler(handler); - #[allow(unsafe_code)] + #[allow(unsafe_code)] unsafe { let _ = sigaction( SIGCHLD, @@ -126,7 +126,7 @@ where let default_action = SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty()); - #[allow(unsafe_code)] + #[allow(unsafe_code)] unsafe { let _ = sigaction(signal, &default_action); }