diff --git a/Cargo.toml b/Cargo.toml index 333efd8..f8c311d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,9 @@ significant_drop_tightening = "allow" # Subjective nursery lint: the suggested map_or/map_or_else rewrites read worse # than the explicit if let/match they replace. option_if_let_else = "allow" +# `assert!(x.is_empty())` in tests is fine; the suggested +# `assert_eq!(x, [] as [T; 0])` only trades a clear check for a type-cast chore. +assert_is_empty = "allow" # The MD5 round functions use the conventional a/b/c/d register names from the # RFC 1321 reference implementation. many_single_char_names = "allow" diff --git a/soulseek-rs-lib/src/client/connection.rs b/soulseek-rs-lib/src/client/connection.rs index cf0bb09..6ec45e0 100644 --- a/soulseek-rs-lib/src/client/connection.rs +++ b/soulseek-rs-lib/src/client/connection.rs @@ -209,33 +209,33 @@ impl Client { /// control. pub fn login(&self) -> Result { info!("Logging in as {}", self.username); - if let Some(handle) = &self.server_handle - && !self.cancel.is_cancelled() - { - let (tx, rx) = std::sync::mpsc::channel(); - let _ = handle.send(ServerMessage::Login { - username: self.username.clone(), - password: self.password.clone(), - version: self.version, - response: tx, - }); + let Some(handle) = &self.server_handle else { + return Err(SoulseekRs::NotConnected); + }; + if self.cancel.is_cancelled() { + return Err(SoulseekRs::NotConnected); + } + let (tx, rx) = std::sync::mpsc::channel(); + let _ = handle.send(ServerMessage::Login { + username: self.username.clone(), + password: self.password.clone(), + version: self.version, + response: tx, + }); - let deadline = Instant::now() + LOGIN_RESPONSE_TIMEOUT; - loop { - match rx.recv_timeout(LOGIN_POLL_INTERVAL) { - Ok(result) => return result, - Err(RecvTimeoutError::Timeout) - if self.cancel.is_cancelled() => - { - return Err(SoulseekRs::NotConnected); - } - Err(RecvTimeoutError::Timeout) - if Instant::now() < deadline => {} - Err(_) => return Err(SoulseekRs::Timeout), + let deadline = Instant::now() + LOGIN_RESPONSE_TIMEOUT; + loop { + match rx.recv_timeout(LOGIN_POLL_INTERVAL) { + Ok(result) => return result, + Err(RecvTimeoutError::Timeout) + if self.cancel.is_cancelled() => + { + return Err(SoulseekRs::NotConnected); } + Err(RecvTimeoutError::Timeout) if Instant::now() < deadline => { + } + Err(_) => return Err(SoulseekRs::Timeout), } - } else { - Err(SoulseekRs::NotConnected) } }