Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Clippy review
Browse files Browse the repository at this point in the history
  • Loading branch information
garious committed Mar 22, 2018
1 parent 7488d19 commit 117ab0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/accountant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl Event {
pub fn get_signature(&self) -> Option<Signature> {
match *self {
Event::Transaction(ref tr) => Some(tr.sig),
Event::Signature { .. } => None,
Event::Timestamp { .. } => None,
Event::Signature { .. } | Event::Timestamp { .. } => None,
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/historian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -55,14 +63,6 @@ impl Historian {
}
}

pub fn reserve_signature(sigs: &mut HashSet<Signature>, sig: &Signature) -> bool {
if sigs.contains(sig) {
return false;
}
sigs.insert(*sig);
true
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions src/streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -83,7 +83,7 @@ impl Packet {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct PacketData {
pub packets: Vec<Packet>,
}
Expand Down

0 comments on commit 117ab0c

Please sign in to comment.