From 4023b5bad4253c0ec118537a607dd6c7a9ac0226 Mon Sep 17 00:00:00 2001 From: soruh Date: Sun, 19 Mar 2023 16:26:56 +0100 Subject: [PATCH] fix clippy complaints --- src/auth.rs | 10 ++++++---- src/client.rs | 4 ++-- src/constants.rs | 2 +- src/main.rs | 16 +++++++--------- src/ports.rs | 12 ++++-------- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 6afe1ba..27f8d6e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -13,10 +13,12 @@ pub async fn dyn_ip_update( ) -> anyhow::Result { debug!(%number, %port, "starting dyn ip update"); - let mut packet = Packet::default(); - packet.header = Header { - kind: PacketKind::DynIpUpdate.raw(), - length: 8, + let mut packet = Packet { + header: Header { + kind: PacketKind::DynIpUpdate.raw(), + length: 8, + }, + data: Vec::new(), }; packet.data.clear(); diff --git a/src/client.rs b/src/client.rs index 1241f23..f9416af 100644 --- a/src/client.rs +++ b/src/client.rs @@ -249,7 +249,7 @@ pub async fn connection_handler( packet, )?; - return Ok(()); + Ok(()) } PacketKind::RemAck => { @@ -313,7 +313,7 @@ pub async fn connection_handler( .await?; } - return Ok(()); + Ok(()) } kind => bail!("unexpected packet: {:?}", kind), diff --git a/src/constants.rs b/src/constants.rs index afcdb33..189ea9c 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -4,7 +4,7 @@ pub const AUTH_TIMEOUT: Duration = Duration::from_secs(30); pub const CALL_ACK_TIMEOUT: Duration = Duration::from_secs(30); pub const CALL_TIMEOUT: Duration = Duration::from_secs(24 * 60 * 60); pub const PORT_RETRY_TIME: Duration = Duration::from_secs(15 * 60); -pub const PORT_OWNERSHIP_TIMEOUT: Duration = Duration::from_secs(1 * 60 * 60); +pub const PORT_OWNERSHIP_TIMEOUT: Duration = Duration::from_secs(60 * 60); pub const PING_TIMEOUT: Duration = Duration::from_secs(30); pub const SEND_PING_INTERVAL: Duration = Duration::from_secs(20); diff --git a/src/main.rs b/src/main.rs index 0d24de1..74e6e81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ fn parse_log_level<'de, D: Deserializer<'de>>(deserializer: D) -> Result>( @@ -72,7 +72,7 @@ fn parse_time_format<'de, D: Deserializer<'de>>( use serde::de::Error; time::format_description::parse_owned::<2>(&String::deserialize(deserializer)?) - .map_err(|err| D::Error::custom(err)) + .map_err(D::Error::custom) } fn maybe_parse_socket_addr<'de, D: Deserializer<'de>>( @@ -82,12 +82,10 @@ fn maybe_parse_socket_addr<'de, D: Deserializer<'de>>( Option::::deserialize(deserializer)? .map(|s| { - Ok::<_, D::Error>( - s.to_socket_addrs() - .map_err(|err| D::Error::custom(err))? - .next() - .ok_or_else(|| D::Error::invalid_length(0, &"one or more"))?, - ) + s.to_socket_addrs() + .map_err(D::Error::custom)? + .next() + .ok_or_else(|| D::Error::invalid_length(0, &"one or more")) }) .transpose() } @@ -97,7 +95,7 @@ fn parse_socket_addr<'de, D: Deserializer<'de>>(deserializer: D) -> Result String { fn format_instant(instant: Instant) -> String { let when = duration_in_hours(instant.elapsed()) + " ago"; - let when = (|| -> anyhow::Result<_> { + (|| -> anyhow::Result<_> { let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)? - instant.elapsed(); let date = time::OffsetDateTime::from_unix_timestamp(timestamp.as_secs() as i64)? .to_offset(*TIME_ZONE_OFFSET.get().unwrap()) @@ -75,9 +75,7 @@ fn format_instant(instant: Instant) -> String { Ok(format!("{date} ({when})")) })() - .unwrap_or(when); - - when + .unwrap_or(when) } fn instant_from_timestamp(timestamp: UnixTimestamp) -> Instant { @@ -292,14 +290,12 @@ impl PortHandler { let is_allocted = self .allocated_ports .iter() - .find(|(_, allocated_port)| *allocated_port == port) - .is_some(); + .any(|(_, allocated_port)| allocated_port == port); let is_errored = self .errored_ports .iter() - .find(|(_, errored_port)| errored_port == port) - .is_some(); + .any(|(_, errored_port)| errored_port == port); !(is_allocted || is_errored) });