From 819dccc0d84ed0490539fb6d9ac40247ccfbbfca Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Thu, 16 Sep 2021 23:57:32 -0700 Subject: [PATCH] style(*) fix clippy warnings --- src/bin/server.rs | 2 +- src/fake_tcp/mod.rs | 6 +++--- src/fake_tcp/packet.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index b578a4f..b0d7f7f 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -78,7 +78,7 @@ async fn main() { tokio::select! { Ok(size) = udp_sock.recv(&mut buf_udp) => { - if let None = sock.send(&buf_udp[..size]).await { + if sock.send(&buf_udp[..size]).await.is_none() { return; } }, diff --git a/src/fake_tcp/mod.rs b/src/fake_tcp/mod.rs index f743e77..7d5ee93 100644 --- a/src/fake_tcp/mod.rs +++ b/src/fake_tcp/mod.rs @@ -108,14 +108,14 @@ impl Socket { } fn build_tcp_packet(&self, flags: u16, payload: Option<&[u8]>) -> Bytes { - return build_tcp_packet( + build_tcp_packet( self.local_addr, self.remote_addr, self.seq.load(Ordering::Relaxed), self.ack.load(Ordering::Relaxed), flags, payload, - ); + ) } pub async fn send(&self, payload: &[u8]) -> Option<()> { @@ -379,7 +379,7 @@ impl Stack { let sender; { let tuples = shared.tuples.lock().unwrap(); - sender = tuples.get(&tuple).map(|c| c.clone()); + sender = tuples.get(&tuple).cloned(); } if let Some(c) = sender { diff --git a/src/fake_tcp/packet.rs b/src/fake_tcp/packet.rs index 283ab76..77262e7 100644 --- a/src/fake_tcp/packet.rs +++ b/src/fake_tcp/packet.rs @@ -47,7 +47,7 @@ pub fn build_tcp_packet( tcp.set_data_offset(TCP_HEADER_LEN as u8 / 4 + if wscale { 1 } else { 0 }); if wscale { let wscale = tcp::TcpOption::wscale(14); - tcp.set_options(&vec![tcp::TcpOption::nop(), wscale]); + tcp.set_options(&[tcp::TcpOption::nop(), wscale]); } if let Some(payload) = payload { @@ -59,11 +59,11 @@ pub fn build_tcp_packet( v4_buf.unsplit(tcp_buf); - return v4_buf.freeze(); + v4_buf.freeze() } -pub fn parse_ipv4_packet<'b>(buf: &'b Bytes) -> (ipv4::Ipv4Packet<'b>, tcp::TcpPacket<'b>) { - let v4 = ipv4::Ipv4Packet::new(&buf).unwrap(); +pub fn parse_ipv4_packet(buf: &Bytes) -> (ipv4::Ipv4Packet, tcp::TcpPacket) { + let v4 = ipv4::Ipv4Packet::new(buf).unwrap(); let tcp = tcp::TcpPacket::new(&buf[IPV4_HEADER_LEN..]).unwrap(); (v4, tcp)