Skip to content

Commit 7cbf453

Browse files
committed
clippy
1 parent f23114d commit 7cbf453

File tree

14 files changed

+42
-44
lines changed

14 files changed

+42
-44
lines changed

common/client-core/src/client/inbound_messages.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl InputMessage {
199199
self.set_max_retransmissions(max_retransmissions);
200200
self
201201
}
202-
202+
#[allow(clippy::expect_used)]
203203
pub fn serialized_size(&self) -> u64 {
204204
bincode::serialized_size(self).expect("failed to get serialized InputMessage size")
205205
+ LENGHT_ENCODING_PREFIX_SIZE as u64
@@ -226,6 +226,7 @@ impl Encoder<InputMessage> for InputMessageCodec {
226226
type Error = ClientCoreError;
227227

228228
fn encode(&mut self, item: InputMessage, buf: &mut BytesMut) -> Result<(), Self::Error> {
229+
#[allow(clippy::expect_used)]
229230
let encoded = bincode::serialize(&item).expect("failed to serialize InputMessage");
230231
let encoded_len = encoded.len() as u32;
231232
let mut encoded_with_len = encoded_len.to_le_bytes().to_vec();
@@ -244,7 +245,7 @@ impl Decoder for InputMessageCodec {
244245
if buf.len() < LENGHT_ENCODING_PREFIX_SIZE {
245246
return Ok(None);
246247
}
247-
248+
#[allow(clippy::expect_used)]
248249
let len = u32::from_le_bytes(
249250
buf[0..LENGHT_ENCODING_PREFIX_SIZE]
250251
.try_into()

common/nym-connection-monitor/src/sync_self_ping.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use std::time::Duration;
55

6-
use futures::StreamExt;
76
use nym_sdk::mixnet::{MixnetClient, MixnetMessageSender, Recipient};
87
use tracing::{debug, error};
98

mixtcp/examples/cloudflare_ping.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::result_large_err)]
12
use mixtcp::{create_device, MixtcpError};
23
use rustls::{pki_types::ServerName, ClientConfig, ClientConnection};
34
use std::{
@@ -97,7 +98,7 @@ fn inspect_tls_packet(data: &[u8]) {
9798
return;
9899
}
99100
let content_type = data[0];
100-
if content_type < 0x14 || content_type > 0x17 {
101+
if !(0x14..=0x17).contains(&content_type) {
101102
return;
102103
}
103104
let version = u16::from_be_bytes([data[1], data[2]]);

mixtcp/examples/https_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::result_large_err)]
12
use mixtcp::{create_device, MixtcpError, NymIprDevice};
23
use nym_sdk::stream_wrapper::IpMixStream;
34
use reqwest::StatusCode;

mixtcp/examples/tls.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::result_large_err)]
12
use mixtcp::{create_device, MixtcpError};
23
use rustls::{pki_types::ServerName, ClientConfig, ClientConnection};
34
use std::{
@@ -97,7 +98,7 @@ fn inspect_tls_packet(data: &[u8]) {
9798
return;
9899
}
99100
let content_type = data[0];
100-
if content_type < 0x14 || content_type > 0x17 {
101+
if !(0x14..=0x17).contains(&content_type) {
101102
return;
102103
}
103104
let version = u16::from_be_bytes([data[1], data[2]]);
@@ -199,7 +200,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
199200
}
200201
}
201202

202-
if start.elapsed().as_secs() % 5 == 0 && start.elapsed().as_millis() % 1000 < 100 {
203+
if start.elapsed().as_secs().is_multiple_of(5) && start.elapsed().as_millis() % 1000 < 100 {
203204
info!(
204205
"State: TCP={:?}, established={}, can_send={}, can_recv={}",
205206
socket.state(),
@@ -224,7 +225,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
224225
let _ = tls_conn.read_tls(socket);
225226
let _ = tls_conn.write_tls(socket);
226227

227-
if start.elapsed().as_secs() % 10 == 0 && start.elapsed().as_millis() % 1000 < 100 {
228+
if start.elapsed().as_secs().is_multiple_of(10)
229+
&& start.elapsed().as_millis() % 1000 < 100
230+
{
228231
info!(
229232
"TLS state: handshaking={}, wants_read={}, wants_write={}",
230233
tls_conn.conn.is_handshaking(),

mixtcp/src/bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl NymIprBridge {
9898
info!("Incoming packet: {} bytes", packet.len());
9999

100100
// Forward to device via channel
101-
if let Err(_) = self.rx_sender.send(packet.to_vec()) {
101+
if self.rx_sender.send(packet.to_vec()).is_err() {
102102
error!("Failed to send packet to device - receiver dropped");
103103
return Err(MixtcpError::ChannelClosed);
104104
}

mixtcp/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ pub async fn create_device(
3131

3232
// Get the allocated IPs before moving the stream - need these for proper packet creation
3333
// further 'up' the flow in the code calling this fn (see examples/tcp_connect.rs).
34-
let allocated_ips = ipr_stream
34+
let allocated_ips = *ipr_stream
3535
.allocated_ips()
36-
.ok_or(MixtcpError::NotConnected)?
37-
.clone();
36+
.ok_or(MixtcpError::NotConnected)?;
3837

3938
// Create channels for device <-> bridge communication
4039
let (tx_to_bridge, tx_from_device) = mpsc::unbounded_channel();

nym-gateway-directory/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub enum Error {
105105

106106
#[error("invalid score value: {0}. Valid values are: offline, low, medium, high")]
107107
InvalidScoreValue(String),
108+
109+
#[error("ips vec empty")]
110+
NoIpsAvailable,
108111
}
109112

110113
impl Error {

nym-gateway-directory/src/gateway_client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl GatewayClient {
166166
.map_err(Box::new)?;
167167

168168
// Gets around diff version imports compiler issue for the moment
169+
#[allow(clippy::expect_used)]
169170
let network_details_compat = {
170171
let json = serde_json::to_string(network_details)
171172
.expect("Failed to serialize network details");
@@ -292,12 +293,13 @@ impl GatewayClient {
292293
debug!("found the following ips for {gateway_identity}: {ips:?}");
293294
if ips.len() == 1 {
294295
// SAFETY: the vector is not empty, so unwrap is fine
296+
#[allow(clippy::unwrap_used)]
295297
Ok(ips.pop().unwrap())
296298
} else {
297299
// chose a random one if there's more than one
298300
// SAFETY: the vector is not empty, so unwrap is fine
299301
let mut rng = thread_rng();
300-
let ip = ips.choose(&mut rng).unwrap();
302+
let ip = ips.choose(&mut rng).ok_or_else(|| Error::NoIpsAvailable)?;
301303
Ok(*ip)
302304
}
303305
}

sdk/rust/nym-sdk/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ pub mod client_pool;
1212
pub mod ip_packet_client;
1313
pub mod mixnet;
1414
pub mod stream_wrapper;
15-
#[deprecated(
16-
note = "Functionality from this module is mostly superceded by the stream_wrapper::MixSocket and stream_wrapper::MixStreamIPR exports. This module is no longer maintained and will be removed in a future release."
17-
)]
1815
pub mod tcp_proxy;
1916

2017
pub use error::{Error, Result};

0 commit comments

Comments
 (0)