From 7f2cb684c981d8146ceae853eab9a4b1a772f549 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 2 Jan 2023 19:01:35 +0100 Subject: [PATCH] fix clippy warnings --- connect/src/spirc.rs | 2 +- core/src/authentication.rs | 2 +- discovery/src/server.rs | 6 +++--- metadata/src/audio/item.rs | 2 +- playback/src/convert.rs | 8 +------- playback/src/lib.rs | 2 +- playback/src/player.rs | 2 +- protocol/build.rs | 2 +- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 84c5e3e6..5705c8c2 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -1138,7 +1138,7 @@ impl SpircTask { self.state.set_status(PlayStatus::kPlayStatusPlay); self.update_state_position(position_ms); self.play_status = SpircPlayStatus::Playing { - nominal_start_time: self.now_ms() as i64 - position_ms as i64, + nominal_start_time: self.now_ms() - position_ms as i64, preloading_of_next_track_triggered, }; } diff --git a/core/src/authentication.rs b/core/src/authentication.rs index b2bcad94..89117860 100644 --- a/core/src/authentication.rs +++ b/core/src/authentication.rs @@ -173,5 +173,5 @@ where D: serde::Deserializer<'de>, { let v: String = serde::Deserialize::deserialize(de)?; - base64::decode(&v).map_err(|e| serde::de::Error::custom(e.to_string())) + base64::decode(v).map_err(|e| serde::de::Error::custom(e.to_string())) } diff --git a/discovery/src/server.rs b/discovery/src/server.rs index faea33a1..379988aa 100644 --- a/discovery/src/server.rs +++ b/discovery/src/server.rs @@ -61,7 +61,7 @@ impl RequestHandler { } fn handle_get_info(&self) -> Response { - let public_key = base64::encode(&self.keys.public_key()); + let public_key = base64::encode(self.keys.public_key()); let device_type: &str = self.config.device_type.into(); let mut active_user = String::new(); if let Some(username) = &self.username { @@ -139,7 +139,7 @@ impl RequestHandler { let encrypted = &encrypted_blob[16..encrypted_blob_len - 20]; let cksum = &encrypted_blob[encrypted_blob_len - 20..encrypted_blob_len]; - let base_key = Sha1::digest(&shared_key); + let base_key = Sha1::digest(shared_key); let base_key = &base_key[..16]; let checksum_key = { @@ -179,7 +179,7 @@ impl RequestHandler { data }; - let credentials = Credentials::with_blob(username, &decrypted, &self.config.device_id)?; + let credentials = Credentials::with_blob(username, decrypted, &self.config.device_id)?; self.tx.send(credentials)?; diff --git a/metadata/src/audio/item.rs b/metadata/src/audio/item.rs index 2a672075..b2789008 100644 --- a/metadata/src/audio/item.rs +++ b/metadata/src/audio/item.rs @@ -109,7 +109,7 @@ impl AudioItem { ) }; - let popularity = track.popularity.max(0).min(100) as u8; + let popularity = track.popularity.clamp(0, 100) as u8; let number = track.number.max(0) as u32; let disc_number = track.disc_number.max(0) as u32; diff --git a/playback/src/convert.rs b/playback/src/convert.rs index 1bc8a88e..a7efe452 100644 --- a/playback/src/convert.rs +++ b/playback/src/convert.rs @@ -76,13 +76,7 @@ impl Converter { let min = -factor; let max = factor - 1.0; - if int_value < min { - min - } else if int_value > max { - max - } else { - int_value - } + int_value.clamp(min, max) } pub fn f64_to_f32(&mut self, samples: &[f64]) -> Vec { diff --git a/playback/src/lib.rs b/playback/src/lib.rs index a52ca2fa..43a5b4f0 100644 --- a/playback/src/lib.rs +++ b/playback/src/lib.rs @@ -15,6 +15,6 @@ pub mod player; pub const SAMPLE_RATE: u32 = 44100; pub const NUM_CHANNELS: u8 = 2; -pub const SAMPLES_PER_SECOND: u32 = SAMPLE_RATE as u32 * NUM_CHANNELS as u32; +pub const SAMPLES_PER_SECOND: u32 = SAMPLE_RATE * NUM_CHANNELS as u32; pub const PAGES_PER_MS: f64 = SAMPLE_RATE as f64 / 1000.0; pub const MS_PER_PAGE: f64 = 1000.0 / SAMPLE_RATE as f64; diff --git a/playback/src/player.rs b/playback/src/player.rs index f0f0d492..3fdf41b7 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -1311,7 +1311,7 @@ impl Future for PlayerInternal { self.send_event(PlayerEvent::PositionCorrection { play_request_id, track_id, - position_ms: new_stream_position_ms as u32, + position_ms: new_stream_position_ms, }); } } diff --git a/protocol/build.rs b/protocol/build.rs index b7c3f44d..b63fa1aa 100644 --- a/protocol/build.rs +++ b/protocol/build.rs @@ -9,7 +9,7 @@ fn out_dir() -> PathBuf { } fn cleanup() { - let _ = fs::remove_dir_all(&out_dir()); + let _ = fs::remove_dir_all(out_dir()); } fn compile() {