fix clippy on basalt code

This commit is contained in:
Alex 2021-10-12 13:28:57 +02:00
parent 74e661febe
commit 940750b5db
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1

View file

@ -52,6 +52,7 @@ impl Peer {
fn cost(&self, seed: &Seed) -> Cost { fn cost(&self, seed: &Seed) -> Cost {
let mut hasher = hash::State::new(); let mut hasher = hash::State::new();
hasher.update(&seed[..]); hasher.update(&seed[..]);
let hasher = hasher;
let mut cost = [0u8; 40]; let mut cost = [0u8; 40];
match self.addr { match self.addr {
@ -59,7 +60,7 @@ impl Peer {
let v4ip = v4addr.ip().octets(); let v4ip = v4addr.ip().octets();
for i in 0..4 { for i in 0..4 {
let mut h = hasher.clone(); let mut h = hasher;
h.update(&v4ip[..i + 1]); h.update(&v4ip[..i + 1]);
cost[i * 8..(i + 1) * 8].copy_from_slice(&h.finalize()[..8]); cost[i * 8..(i + 1) * 8].copy_from_slice(&h.finalize()[..8]);
} }
@ -68,7 +69,7 @@ impl Peer {
let v6ip = v6addr.ip().octets(); let v6ip = v6addr.ip().octets();
for i in 0..4 { for i in 0..4 {
let mut h = hasher.clone(); let mut h = hasher;
h.update(&v6ip[..i + 2]); h.update(&v6ip[..i + 2]);
cost[i * 8..(i + 1) * 8].copy_from_slice(&h.finalize()[..8]); cost[i * 8..(i + 1) * 8].copy_from_slice(&h.finalize()[..8]);
} }
@ -76,7 +77,7 @@ impl Peer {
} }
{ {
let mut h5 = hasher.clone(); let mut h5 = hasher;
h5.update(&format!("{} {}", self.addr, hex::encode(self.id)).into_bytes()[..]); h5.update(&format!("{} {}", self.addr, hex::encode(self.id)).into_bytes()[..]);
cost[32..40].copy_from_slice(&h5.finalize()[..8]); cost[32..40].copy_from_slice(&h5.finalize()[..8]);
} }
@ -115,8 +116,7 @@ impl BasaltView {
fn current_peers(&self) -> HashSet<Peer> { fn current_peers(&self) -> HashSet<Peer> {
self.slots self.slots
.iter() .iter()
.filter(|s| s.peer.is_some()) .filter_map(|s| s.peer)
.map(|s| s.peer.unwrap().clone())
.collect::<HashSet<_>>() .collect::<HashSet<_>>()
} }
fn current_peers_vec(&self) -> Vec<Peer> { fn current_peers_vec(&self) -> Vec<Peer> {
@ -131,7 +131,7 @@ impl BasaltView {
.filter(|(_i, s)| s.peer.is_some()) .filter(|(_i, s)| s.peer.is_some())
.map(|(i, _s)| i) .map(|(i, _s)| i)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if possibles.len() == 0 { if possibles.is_empty() {
vec![] vec![]
} else { } else {
let mut ret = vec![]; let mut ret = vec![];
@ -290,7 +290,7 @@ impl Basalt {
let basalt2 = basalt.clone(); let basalt2 = basalt.clone();
netapp.add_msg_handler::<PushMessage, _, _>(move |_from: NodeID, push_msg: PushMessage| { netapp.add_msg_handler::<PushMessage, _, _>(move |_from: NodeID, push_msg: PushMessage| {
basalt2.handle_peer_list(&push_msg.peers[..]); basalt2.handle_peer_list(&push_msg.peers[..]);
async move { () } async move { }
}); });
basalt basalt