From 0ff9cf9cb0a43fd6cea8289dcb8df7e707e90ba1 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Wed, 9 Jun 2021 20:18:46 +0530 Subject: [PATCH] addressing clippy lints --- src/cache/hashcache.rs | 10 +++++----- src/master/embedded/counter.rs | 2 +- src/master/embedded/master.rs | 13 ++++++------- src/master/redis/connection.rs | 19 ++++++------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/cache/hashcache.rs b/src/cache/hashcache.rs index 750d216..1d857ee 100644 --- a/src/cache/hashcache.rs +++ b/src/cache/hashcache.rs @@ -48,7 +48,7 @@ impl HashCache { // retrive [PoWConfig] from cache. Deletes config post retrival fn retrive_pow_config(&mut self, string: String) -> CaptchaResult> { if let Some(difficulty_factor) = self.remove_pow_config(&string) { - Ok(Some(difficulty_factor.to_owned())) + Ok(Some(difficulty_factor)) } else { Ok(None) } @@ -69,9 +69,9 @@ impl HashCache { fn verify_captcha_result(&mut self, challenge: VerifyCaptchaResult) -> CaptchaResult { if let Some(captcha_id) = self.remove_cache_result(&challenge.token) { if captcha_id == challenge.key { - return Ok(true); + Ok(true) } else { - return Ok(false); + Ok(false) } } else { Ok(false) @@ -101,7 +101,7 @@ impl Handler for HashCache { let addr = ctx.address(); let del_msg = DeletePoW(msg.string.clone()); - let duration: Duration = Duration::new(msg.duration.clone(), 0); + let duration: Duration = Duration::new(msg.duration, 0); let wait_for = async move { //sleep(duration).await; delay_for(duration).await; @@ -144,7 +144,7 @@ impl Handler for HashCache { token: msg.token.clone(), }; - let duration: Duration = Duration::new(msg.duration.clone(), 0); + let duration: Duration = Duration::new(msg.duration, 0); let wait_for = async move { //sleep(duration).await; delay_for(duration).await; diff --git a/src/master/embedded/counter.rs b/src/master/embedded/counter.rs index ede5163..888f34c 100644 --- a/src/master/embedded/counter.rs +++ b/src/master/embedded/counter.rs @@ -284,7 +284,7 @@ pub mod tests { Some(CaptchaError::PleaseSetValue("defense".into())) ); - let m = MCaptchaBuilder::default().defense(defense.clone()).build(); + let m = MCaptchaBuilder::default().defense(defense).build(); assert_eq!( m.err(), Some(CaptchaError::PleaseSetValue("duration".into())) diff --git a/src/master/embedded/master.rs b/src/master/embedded/master.rs index a6d3f66..4772266 100644 --- a/src/master/embedded/master.rs +++ b/src/master/embedded/master.rs @@ -45,7 +45,7 @@ impl MasterTrait for Master {} impl Master { /// add [Counter] actor to [Master] pub fn add_site(&mut self, addr: Addr, id: String) { - self.sites.insert(id, (None, addr.to_owned())); + self.sites.insert(id, (None, addr)); } /// create new master @@ -58,7 +58,7 @@ impl Master { } /// get [Counter] actor from [Master] - pub fn get_site<'a, 'b>(&'a mut self, id: &'b str) -> Option> { + pub fn get_site(&mut self, id: &str) -> Option> { let mut r = None; if let Some((read_val, addr)) = self.sites.get_mut(id) { r = Some(addr.clone()); @@ -111,7 +111,7 @@ impl Handler for Master { ctx.spawn(fut); } } - return MessageResult(rx); + MessageResult(rx) } } @@ -125,10 +125,9 @@ impl Handler for Master { fn handle(&mut self, m: GetSite, _ctx: &mut Self::Context) -> Self::Result { let addr = self.get_site(&m.0); - if addr.is_none() { - return MessageResult(None); - } else { - return MessageResult(Some(addr.unwrap().clone())); + match addr { + None => MessageResult(None), + Some(addr) => MessageResult(Some(addr)), } } } diff --git a/src/master/redis/connection.rs b/src/master/redis/connection.rs index a700a27..ab57d55 100644 --- a/src/master/redis/connection.rs +++ b/src/master/redis/connection.rs @@ -77,24 +77,17 @@ impl MCaptchaRedisConnection { let commands = vec![ADD_VISITOR, ADD_CAPTCHA, DEL, CAPTCHA_EXISTS, GET]; for cmd in commands.iter() { - match self + if let Value::Bulk(mut val) = self .0 .exec(redis::cmd("COMMAND").arg(&["INFO", cmd])) .await .unwrap() { - Value::Bulk(mut val) => { - match val.pop() { - Some(Value::Nil) => { - return Err(CaptchaError::MCaptchaRediSModuleCommandNotFound( - cmd.to_string(), - )) - } - _ => (), - }; - } - - _ => (), + if let Some(Value::Nil) = val.pop() { + return Err(CaptchaError::MCaptchaRediSModuleCommandNotFound( + cmd.to_string(), + )); + }; }; }