diff --git a/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs b/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs index 48047075..4eed1b18 100644 --- a/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs +++ b/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs @@ -70,7 +70,7 @@ impl Socks5UdpClient { send_buf.put_slice(buf); let n = self.socket.send(&send_buf).await?; - Ok(if n <= header_len { 0 } else { n - header_len }) + Ok(n.saturating_sub(header_len)) } /// Returns a future that receives a single datagram on the socket. On success, the future resolves to the number of bytes read and the origin. diff --git a/crates/shadowsocks/src/config.rs b/crates/shadowsocks/src/config.rs index 852ffc7a..c3f4597c 100644 --- a/crates/shadowsocks/src/config.rs +++ b/crates/shadowsocks/src/config.rs @@ -129,7 +129,7 @@ impl FromStr for Mode { struct ModeVisitor; -impl<'de> serde::de::Visitor<'de> for ModeVisitor { +impl serde::de::Visitor<'_> for ModeVisitor { type Value = Mode; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -1078,7 +1078,7 @@ impl Display for ServerAddr { struct ServerAddrVisitor; -impl<'de> serde::de::Visitor<'de> for ServerAddrVisitor { +impl serde::de::Visitor<'_> for ServerAddrVisitor { type Value = ServerAddr; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -1259,7 +1259,7 @@ impl Display for ManagerAddr { struct ManagerAddrVisitor; -impl<'de> serde::de::Visitor<'de> for ManagerAddrVisitor { +impl serde::de::Visitor<'_> for ManagerAddrVisitor { type Value = ManagerAddr; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/crates/shadowsocks/src/dns_resolver/resolver.rs b/crates/shadowsocks/src/dns_resolver/resolver.rs index dfd78b45..e42e79c3 100644 --- a/crates/shadowsocks/src/dns_resolver/resolver.rs +++ b/crates/shadowsocks/src/dns_resolver/resolver.rs @@ -315,7 +315,7 @@ impl DnsResolver { } } - impl<'x, 'y> Drop for ResolverLogger<'x, 'y> { + impl Drop for ResolverLogger<'_, '_> { fn drop(&mut self) { match self.start_time { Some(start_time) => { diff --git a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/mod.rs b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/mod.rs index 56ae3a01..883986ae 100644 --- a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/mod.rs +++ b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/mod.rs @@ -86,7 +86,7 @@ pub enum TcpRequestHeaderRef<'a> { Aead2022(Aead2022TcpRequestHeaderRef<'a>), } -impl<'a> TcpRequestHeaderRef<'a> { +impl TcpRequestHeaderRef<'_> { pub fn write_to_buf(&self, buf: &mut B) { match *self { TcpRequestHeaderRef::Stream(ref h) => h.write_to_buf(buf), diff --git a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v1.rs b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v1.rs index 7c002923..2eaa81d3 100644 --- a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v1.rs +++ b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v1.rs @@ -33,7 +33,7 @@ pub struct StreamTcpRequestHeaderRef<'a> { pub addr: &'a Address, } -impl<'a> StreamTcpRequestHeaderRef<'a> { +impl StreamTcpRequestHeaderRef<'_> { pub fn write_to_buf(&self, buf: &mut B) { self.addr.write_to_buf(buf); } diff --git a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v2.rs b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v2.rs index 469488d5..656306d5 100644 --- a/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v2.rs +++ b/crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v2.rs @@ -72,7 +72,7 @@ pub struct Aead2022TcpRequestHeaderRef<'a> { pub padding_size: u16, } -impl<'a> Aead2022TcpRequestHeaderRef<'a> { +impl Aead2022TcpRequestHeaderRef<'_> { pub fn write_to_buf(&self, buf: &mut B) { assert!( self.padding_size as usize <= MAX_PADDING_SIZE, diff --git a/crates/shadowsocks/src/relay/tcprelay/utils.rs b/crates/shadowsocks/src/relay/tcprelay/utils.rs index 0b267ce1..e37d8c66 100644 --- a/crates/shadowsocks/src/relay/tcprelay/utils.rs +++ b/crates/shadowsocks/src/relay/tcprelay/utils.rs @@ -240,7 +240,7 @@ where } } -impl<'a, A, B> Future for CopyBidirectional<'a, A, B> +impl Future for CopyBidirectional<'_, A, B> where A: AsyncRead + AsyncWrite + Unpin + ?Sized, B: AsyncRead + AsyncWrite + Unpin + ?Sized, diff --git a/crates/shadowsocks/src/relay/udprelay/compat.rs b/crates/shadowsocks/src/relay/udprelay/compat.rs index fd17f28f..8dec3e29 100644 --- a/crates/shadowsocks/src/relay/udprelay/compat.rs +++ b/crates/shadowsocks/src/relay/udprelay/compat.rs @@ -81,7 +81,7 @@ pub struct RecvFut<'a, S: DatagramReceive + ?Sized> { buf: &'a mut [u8], } -impl<'a, S: DatagramReceive + ?Sized> Future for RecvFut<'a, S> { +impl Future for RecvFut<'_, S> { type Output = io::Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -101,7 +101,7 @@ pub struct RecvFromFut<'a, S: DatagramReceive + ?Sized> { buf: &'a mut [u8], } -impl<'a, S: DatagramReceive + ?Sized> Future for RecvFromFut<'a, S> { +impl Future for RecvFromFut<'_, S> { type Output = io::Result<(usize, SocketAddr)>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -118,7 +118,7 @@ pub struct RecvReadyFut<'a, S: DatagramReceive + ?Sized> { io: &'a S, } -impl<'a, S: DatagramReceive + ?Sized> Future for RecvReadyFut<'a, S> { +impl Future for RecvReadyFut<'_, S> { type Output = io::Result<()>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -132,7 +132,7 @@ pub struct SendFut<'a, S: DatagramSend + ?Sized> { buf: &'a [u8], } -impl<'a, S: DatagramSend + ?Sized> Future for SendFut<'a, S> { +impl Future for SendFut<'_, S> { type Output = io::Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -147,7 +147,7 @@ pub struct SendToFut<'a, S: DatagramSend + ?Sized> { buf: &'a [u8], } -impl<'a, S: DatagramSend + ?Sized> Future for SendToFut<'a, S> { +impl Future for SendToFut<'_, S> { type Output = io::Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -160,7 +160,7 @@ pub struct SendReadyFut<'a, S: DatagramSend + ?Sized> { io: &'a S, } -impl<'a, S: DatagramSend + ?Sized> Future for SendReadyFut<'a, S> { +impl Future for SendReadyFut<'_, S> { type Output = io::Result<()>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll {