From 117ab0c14112d1d8c5d0f4ab3216a7c20441732b Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 22 Mar 2018 14:50:24 -0600 Subject: [PATCH] Clippy review --- src/accountant.rs | 4 ++-- src/event.rs | 3 +-- src/historian.rs | 23 ++++++++++++----------- src/streamer.rs | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/accountant.rs b/src/accountant.rs index 8bdfd51fa..bdad3cf6b 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -9,7 +9,7 @@ use plan::{Plan, Witness}; use transaction::Transaction; use signature::{KeyPair, PublicKey, Signature}; use mint::Mint; -use historian::{reserve_signature, Historian}; +use historian::Historian; use recorder::Signal; use std::sync::mpsc::SendError; use std::collections::{HashMap, HashSet}; @@ -116,7 +116,7 @@ impl Accountant { tr: &Transaction, allow_deposits: bool, ) -> Result<()> { - if !reserve_signature(&mut self.historian.signatures, &tr.sig) { + if !self.historian.reserve_signature(&tr.sig) { return Err(AccountingError::InvalidTransferSignature); } diff --git a/src/event.rs b/src/event.rs index bfaa58c87..8afa18b21 100644 --- a/src/event.rs +++ b/src/event.rs @@ -35,8 +35,7 @@ impl Event { pub fn get_signature(&self) -> Option { match *self { Event::Transaction(ref tr) => Some(tr.sig), - Event::Signature { .. } => None, - Event::Timestamp { .. } => None, + Event::Signature { .. } | Event::Timestamp { .. } => None, } } diff --git a/src/historian.rs b/src/historian.rs index a6a3b94de..a35f41d83 100644 --- a/src/historian.rs +++ b/src/historian.rs @@ -32,6 +32,14 @@ impl Historian { } } + pub fn reserve_signature(&mut self, sig: &Signature) -> bool { + if self.signatures.contains(sig) { + return false; + } + self.signatures.insert(*sig); + true + } + /// A background thread that will continue tagging received Event messages and /// sending back Entry messages until either the receiver or sender channel is closed. fn create_recorder( @@ -55,14 +63,6 @@ impl Historian { } } -pub fn reserve_signature(sigs: &mut HashSet, sig: &Signature) -> bool { - if sigs.contains(sig) { - return false; - } - sigs.insert(*sig); - true -} - #[cfg(test)] mod tests { use super::*; @@ -112,10 +112,11 @@ mod tests { #[test] fn test_duplicate_event_signature() { - let mut sigs = HashSet::new(); + let zero = Hash::default(); + let mut hist = Historian::new(&zero, None); let sig = Signature::default(); - assert!(reserve_signature(&mut sigs, &sig)); - assert!(!reserve_signature(&mut sigs, &sig)); + assert!(hist.reserve_signature(&sig)); + assert!(!hist.reserve_signature(&sig)); } #[test] diff --git a/src/streamer.rs b/src/streamer.rs index 14e110588..54f631b7b 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -68,10 +68,10 @@ impl Packet { match *a { SocketAddr::V4(v4) => { let ip = v4.ip().octets(); - self.addr[0] = ip[0] as u16; - self.addr[1] = ip[1] as u16; - self.addr[2] = ip[2] as u16; - self.addr[3] = ip[3] as u16; + self.addr[0] = u16::from(ip[0]); + self.addr[1] = u16::from(ip[1]); + self.addr[2] = u16::from(ip[2]); + self.addr[3] = u16::from(ip[3]); self.port = a.port(); } SocketAddr::V6(v6) => { @@ -83,7 +83,7 @@ impl Packet { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct PacketData { pub packets: Vec, }