style(*) fix clippy warnings

This commit is contained in:
Datong Sun 2021-09-16 23:57:32 -07:00 committed by Datong Sun
parent 44b7c0f55e
commit 819dccc0d8
3 changed files with 8 additions and 8 deletions

View File

@ -78,7 +78,7 @@ async fn main() {
tokio::select! { tokio::select! {
Ok(size) = udp_sock.recv(&mut buf_udp) => { 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; return;
} }
}, },

View File

@ -108,14 +108,14 @@ impl Socket {
} }
fn build_tcp_packet(&self, flags: u16, payload: Option<&[u8]>) -> Bytes { fn build_tcp_packet(&self, flags: u16, payload: Option<&[u8]>) -> Bytes {
return build_tcp_packet( build_tcp_packet(
self.local_addr, self.local_addr,
self.remote_addr, self.remote_addr,
self.seq.load(Ordering::Relaxed), self.seq.load(Ordering::Relaxed),
self.ack.load(Ordering::Relaxed), self.ack.load(Ordering::Relaxed),
flags, flags,
payload, payload,
); )
} }
pub async fn send(&self, payload: &[u8]) -> Option<()> { pub async fn send(&self, payload: &[u8]) -> Option<()> {
@ -379,7 +379,7 @@ impl Stack {
let sender; let sender;
{ {
let tuples = shared.tuples.lock().unwrap(); let tuples = shared.tuples.lock().unwrap();
sender = tuples.get(&tuple).map(|c| c.clone()); sender = tuples.get(&tuple).cloned();
} }
if let Some(c) = sender { if let Some(c) = sender {

View File

@ -47,7 +47,7 @@ pub fn build_tcp_packet(
tcp.set_data_offset(TCP_HEADER_LEN as u8 / 4 + if wscale { 1 } else { 0 }); tcp.set_data_offset(TCP_HEADER_LEN as u8 / 4 + if wscale { 1 } else { 0 });
if wscale { if wscale {
let wscale = tcp::TcpOption::wscale(14); 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 { if let Some(payload) = payload {
@ -59,11 +59,11 @@ pub fn build_tcp_packet(
v4_buf.unsplit(tcp_buf); 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>) { pub fn parse_ipv4_packet(buf: &Bytes) -> (ipv4::Ipv4Packet, tcp::TcpPacket) {
let v4 = ipv4::Ipv4Packet::new(&buf).unwrap(); let v4 = ipv4::Ipv4Packet::new(buf).unwrap();
let tcp = tcp::TcpPacket::new(&buf[IPV4_HEADER_LEN..]).unwrap(); let tcp = tcp::TcpPacket::new(&buf[IPV4_HEADER_LEN..]).unwrap();
(v4, tcp) (v4, tcp)