From a62744a1773d2cd9dd0e2adb8323e8e759b7e285 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 19 Feb 2020 15:33:37 +0000 Subject: [PATCH] Fixed clippy warnings --- common/clients/mix-client/src/packet.rs | 2 +- common/healthcheck/src/path_check.rs | 8 ++++---- common/healthcheck/src/result.rs | 10 +++------- common/healthcheck/src/score.rs | 2 +- nym-client/src/sockets/tcp.rs | 4 ++-- nym-client/src/sockets/ws.rs | 7 ++----- sfw-provider/sfw-provider-requests/src/responses.rs | 2 +- sfw-provider/src/provider/mod.rs | 3 +-- 8 files changed, 15 insertions(+), 23 deletions(-) diff --git a/common/clients/mix-client/src/packet.rs b/common/clients/mix-client/src/packet.rs index 8fab9589c3..5132d4cb92 100644 --- a/common/clients/mix-client/src/packet.rs +++ b/common/clients/mix-client/src/packet.rs @@ -62,7 +62,7 @@ pub fn encapsulate_message( average_delay: time::Duration, ) -> Result<(SocketAddr, SphinxPacket), SphinxPacketEncapsulationError> { let mut providers = topology.providers(); - if providers.len() == 0 { + if providers.is_empty() { return Err(SphinxPacketEncapsulationError::NoValidProvidersError); } // unwrap is fine here as we asserted there is at least single provider diff --git a/common/healthcheck/src/path_check.rs b/common/healthcheck/src/path_check.rs index 43f4ef329f..79f2f80537 100644 --- a/common/healthcheck/src/path_check.rs +++ b/common/healthcheck/src/path_check.rs @@ -73,7 +73,7 @@ impl PathChecker { // iteration is used to distinguish packets sent through the same path (as the healthcheck // may try to send say 10 packets through given path) - fn unique_path_key(path: &Vec, check_id: [u8; 16], iteration: u8) -> Vec { + fn unique_path_key(path: &[SphinxNode], check_id: [u8; 16], iteration: u8) -> Vec { check_id .iter() .cloned() @@ -173,8 +173,8 @@ impl PathChecker { self.update_path_statuses(provider_messages); } - pub(crate) async fn send_test_packet(&mut self, path: &Vec, iteration: u8) { - if path.len() == 0 { + pub(crate) async fn send_test_packet(&mut self, path: &[SphinxNode], iteration: u8) { + if path.is_empty() { warn!("trying to send test packet through an empty path!"); return; } @@ -221,7 +221,7 @@ impl PathChecker { let first_node_client = self .layer_one_clients .entry(first_node_key) - .or_insert(Some(mix_client::MixClient::new())); + .or_insert_with(|| Some(mix_client::MixClient::new())); if first_node_client.is_none() { debug!("we can ignore this path as layer one mix is inaccessible"); diff --git a/common/healthcheck/src/result.rs b/common/healthcheck/src/result.rs index e1f8ad969c..2db51ddc3a 100644 --- a/common/healthcheck/src/result.rs +++ b/common/healthcheck/src/result.rs @@ -16,7 +16,7 @@ impl std::fmt::Display for HealthCheckResult { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { write!(f, "NETWORK HEALTH\n==============\n")?; for score in self.0.iter() { - write!(f, "{}\n", score)? + writeln!(f, "{}", score)? } Ok(()) } @@ -34,12 +34,8 @@ impl HealthCheckResult { let health = mixes .into_iter() - .map(|node| NodeScore::from_mixnode(node)) - .chain( - providers - .into_iter() - .map(|node| NodeScore::from_provider(node)), - ) + .map(NodeScore::from_mixnode) + .chain(providers.into_iter().map(NodeScore::from_provider)) .collect(); HealthCheckResult(health) diff --git a/common/healthcheck/src/score.rs b/common/healthcheck/src/score.rs index 7262d4ee0d..5cfa6cd811 100644 --- a/common/healthcheck/src/score.rs +++ b/common/healthcheck/src/score.rs @@ -110,7 +110,7 @@ impl NodeScore { pub_key: NodeAddressBytes::from_base58_string(node.pub_key), addresses: vec![node.mixnet_listener, node.client_listener], version: node.version, - layer: format!("provider"), + layer: "provider".to_string(), packets_sent: 0, packets_received: 0, } diff --git a/nym-client/src/sockets/tcp.rs b/nym-client/src/sockets/tcp.rs index 9d9f6d3bd1..28987ad90b 100644 --- a/nym-client/src/sockets/tcp.rs +++ b/nym-client/src/sockets/tcp.rs @@ -125,7 +125,7 @@ impl ClientRequest { Err(e) => { warn!("Failed to fetch client messages - {:?}", e); return ServerResponse::Error { - message: format!("Server failed to receive messages").to_string(), + message: "Server failed to receive messages".to_string(), }; } }; @@ -275,7 +275,7 @@ async fn accept_connection( topology: topology.clone(), msg_input: msg_input.clone(), msg_query: msg_query.clone(), - self_address: self_address.clone(), + self_address, }; match handle_connection(&buf[..n], request_handling_data).await { Ok(res) => res, diff --git a/nym-client/src/sockets/ws.rs b/nym-client/src/sockets/ws.rs index 73d8df3898..9315ac80a1 100644 --- a/nym-client/src/sockets/ws.rs +++ b/nym-client/src/sockets/ws.rs @@ -239,7 +239,7 @@ impl ClientRequest { Err(e) => { warn!("Failed to fetch client messages - {:?}", e); return ServerResponse::Error { - message: format!("Server failed to receive messages").to_string(), + message: "Server failed to receive messages".to_string(), }; } }; @@ -353,10 +353,7 @@ async fn accept_connection( } }; - let mut should_close = false; - if message.is_close() { - should_close = true; - } + let should_close = message.is_close(); if let Err(err) = msg_tx.unbounded_send(message) { error!( diff --git a/sfw-provider/sfw-provider-requests/src/responses.rs b/sfw-provider/sfw-provider-requests/src/responses.rs index 6a181ffedc..4135ed06e4 100644 --- a/sfw-provider/sfw-provider-requests/src/responses.rs +++ b/sfw-provider/sfw-provider-requests/src/responses.rs @@ -72,7 +72,7 @@ impl ProviderResponse for PullResponse { return Err(ProviderResponseError::UnmarshalErrorInvalidLength); } - let mut bytes_copy = bytes.clone(); + let mut bytes_copy = bytes; let num_msgs = read_be_u16(&mut bytes_copy); // can we read all lengths of messages? diff --git a/sfw-provider/src/provider/mod.rs b/sfw-provider/src/provider/mod.rs index 01489211b1..12673ab126 100644 --- a/sfw-provider/src/provider/mod.rs +++ b/sfw-provider/src/provider/mod.rs @@ -63,7 +63,7 @@ impl ClientLedger { } fn has_token(&self, auth_token: &AuthToken) -> bool { - return self.0.contains_key(auth_token); + self.0.contains_key(auth_token) } fn insert_token( @@ -155,7 +155,6 @@ impl ServiceProvider { ) .unwrap_or_else(|e| { error!("failed to store processed sphinx message; err = {:?}", e); - return; }); } Err(e) => {