From f7c628c7e1ea766b0556c684837fbad3daca79a3 Mon Sep 17 00:00:00 2001 From: Atmajeet Kaur Date: Tue, 18 Oct 2016 15:39:40 +0200 Subject: [PATCH] some clippy-suggested improvements --- src/gitignore.rs | 31 +++++++++++++------------------ src/main.rs | 18 ++++++++---------- src/notification_filter.rs | 6 +++--- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/gitignore.rs b/src/gitignore.rs index 85e9183..f9887af 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -64,7 +64,7 @@ impl PatternSet { let mut excluded = false; let has_whitelistings = self.patterns.iter().any(|p| p.whitelist); - for pattern in self.patterns.iter() { + for pattern in &self.patterns { let matched = pattern.matches(path); if matched { @@ -90,23 +90,20 @@ impl Pattern { fn new(pattern: &str, root: &Path) -> Result { let mut normalized = String::from(pattern); - let mut whitelisted = false; - if normalized.starts_with("!") { + let whitelisted = if normalized.starts_with('!') { normalized.remove(0); - whitelisted = true; - } + true + } else { false }; - let mut anchored = false; - if normalized.starts_with("/") { + let anchored = if normalized.starts_with('/') { normalized.remove(0); - anchored = true; - } + true + } else { false }; - let mut directory = false; - if normalized.ends_with("/") { + let directory = if normalized.ends_with('/') { normalized.pop(); - directory = true; - } + true + } else { false }; if normalized.starts_with("\\#") || normalized.starts_with("\\!") { normalized.remove(0); @@ -145,15 +142,13 @@ impl Pattern { None => false } } - else if !self.str.contains("/") { + else if !self.str.contains('/') { result = stripped_path.iter().any(|c| { self.pattern.matches_path_with(Path::new(c), &options) }); } - else { - if self.pattern.matches_path_with(stripped_path, &options) { - result = true; - } + else if self.pattern.matches_path_with(stripped_path, &options) { + result = true; } result diff --git a/src/main.rs b/src/main.rs index 3141e2a..d95a417 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,10 +76,11 @@ fn get_args<'a>() -> ArgMatches<'a> { fn init_logger(debug: bool) { let mut log_builder = env_logger::LogBuilder::new(); - let mut level = log::LogLevelFilter::Warn; - if debug { - level = log::LogLevelFilter::Debug; - } + let level = if debug { + log::LogLevelFilter::Debug + } else { + log::LogLevelFilter::Warn + }; log_builder .format(|r| format!("*** {}", r.args())) @@ -166,7 +167,7 @@ fn wait(rx: &Receiver, filter: &NotificationFilter) -> Result, filter: &NotificationFilter) -> Result continue, - Err(_) => break, - } + while let Ok(_) = rx.try_recv() { + // nothing to do here } return Ok(e); diff --git a/src/notification_filter.rs b/src/notification_filter.rs index c4662a6..f5dcd2c 100644 --- a/src/notification_filter.rs +++ b/src/notification_filter.rs @@ -33,7 +33,7 @@ impl NotificationFilter { pub fn add_extension(&mut self, extensions: &str) -> Result<(), NotificationError> { let patterns: Vec = extensions - .split(",") + .split(',') .filter(|ext| !ext.is_empty()) .map(|ext| format!("*.{}", ext.replace(".", ""))) .collect(); @@ -108,11 +108,11 @@ impl NotificationFilter { } } - if self.filters.len() > 0 { + if !self.filters.is_empty() { debug!("Ignoring {:?}: did not match any given filters", path); } - self.filters.len() > 0 + !self.filters.is_empty() } }