diff --git a/common/clients/directory-client/src/presence/mod.rs b/common/clients/directory-client/src/presence/mod.rs index b595953758..99d23ca130 100644 --- a/common/clients/directory-client/src/presence/mod.rs +++ b/common/clients/directory-client/src/presence/mod.rs @@ -29,11 +29,10 @@ impl NymTopology for Topology { }; let directory = Client::new(directory_config); - let topology = directory + directory .presence_topology .get() - .expect("Failed to retrieve network topology."); - topology + .expect("Failed to retrieve network topology.") } fn new_from_nodes( diff --git a/common/config/src/lib.rs b/common/config/src/lib.rs index 4cf0cadc37..f5c8c0c032 100644 --- a/common/config/src/lib.rs +++ b/common/config/src/lib.rs @@ -46,19 +46,19 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned { }?; fs::write( - custom_location.unwrap_or(self.config_directory().join(Self::config_file_name())), + custom_location + .unwrap_or_else(|| self.config_directory().join(Self::config_file_name())), templated_config, ) } fn load_from_file(custom_location: Option, id: Option<&str>) -> io::Result { let config_contents = fs::read_to_string( - custom_location.unwrap_or(Self::default_config_directory(id).join("config.toml")), + custom_location + .unwrap_or_else(|| Self::default_config_directory(id).join("config.toml")), )?; - let parsing_result = toml::from_str(&config_contents) - .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)); - - parsing_result + toml::from_str(&config_contents) + .map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err)) } } diff --git a/common/topology/src/lib.rs b/common/topology/src/lib.rs index 3067b30b47..5edba93d7d 100644 --- a/common/topology/src/lib.rs +++ b/common/topology/src/lib.rs @@ -30,7 +30,7 @@ pub trait NymTopology: Sized + std::fmt::Debug + Send + Sync { } highest_layer = max(highest_layer, mix.layer); - let layer_nodes = layered_topology.entry(mix.layer).or_insert(Vec::new()); + let layer_nodes = layered_topology.entry(mix.layer).or_insert_with(Vec::new); layer_nodes.push(mix); } @@ -40,12 +40,12 @@ pub trait NymTopology: Sized + std::fmt::Debug + Send + Sync { if !layered_topology.contains_key(&layer) { missing_layers.push(layer); } - if layered_topology[&layer].len() == 0 { + if layered_topology[&layer].is_empty() { missing_layers.push(layer); } } - if missing_layers.len() > 0 { + if !missing_layers.is_empty() { return Err(NymTopologyError::MissingLayerError(missing_layers)); } @@ -112,10 +112,7 @@ pub trait NymTopology: Sized + std::fmt::Debug + Send + Sync { } fn can_construct_path_through(&self) -> bool { - match self.make_layered_topology() { - Ok(_) => true, - Err(_) => false, - } + self.make_layered_topology().is_ok() } } diff --git a/mixnode/src/mix_peer.rs b/mixnode/src/mix_peer.rs index 8a8579a780..82be36c475 100644 --- a/mixnode/src/mix_peer.rs +++ b/mixnode/src/mix_peer.rs @@ -34,13 +34,12 @@ impl MixPeer { } pub async fn send(&self, bytes: Vec) -> Result<(), Box> { - let next_hop_address = self.connection.clone(); - let mut stream = tokio::net::TcpStream::connect(next_hop_address).await?; + let mut stream = tokio::net::TcpStream::connect(self.connection).await?; stream.write_all(&bytes).await?; Ok(()) } - pub fn to_string(&self) -> String { + pub fn stringify(&self) -> String { self.connection.to_string() } } diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 2f6f9dccac..9244022302 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -135,7 +135,7 @@ impl PacketProcessor { if forwarding_data .sent_metrics_tx - .send(forwarding_data.recipient.to_string()) + .send(forwarding_data.recipient.stringify()) .await .is_err() {