From 125c803fa713e728c2f712c222ce00b7a7131d7b Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 9 Jan 2023 00:43:53 +0000 Subject: [PATCH] Chore: Apply latest nightly clippy lints --- src/driver/connection/error.rs | 4 ++-- src/driver/connection/mod.rs | 5 ++--- src/driver/retry/strategy.rs | 12 ++---------- src/input/adapters/async_adapter.rs | 2 +- src/input/adapters/cached/error.rs | 12 ++++++------ src/input/error.rs | 5 ++--- src/input/sources/http.rs | 2 +- src/tracks/command.rs | 8 ++++---- src/tracks/error.rs | 2 +- 9 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/driver/connection/error.rs b/src/driver/connection/error.rs index 7690e7e..7b87bde 100644 --- a/src/driver/connection/error.rs +++ b/src/driver/connection/error.rs @@ -109,8 +109,8 @@ impl fmt::Display for Error { Self::IllegalIp => write!(f, "IP discovery/NAT punching response had bad IP value"), Self::Io(e) => e.fmt(f), Self::Json(e) => e.fmt(f), - Self::InterconnectFailure(e) => write!(f, "failed to contact other task ({:?})", e), - Self::Ws(e) => write!(f, "websocket issue ({:?}).", e), + Self::InterconnectFailure(e) => write!(f, "failed to contact other task ({e:?})"), + Self::Ws(e) => write!(f, "websocket issue ({e:?})."), Self::TimedOut => write!(f, "connection attempt timed out"), } } diff --git a/src/driver/connection/mod.rs b/src/driver/connection/mod.rs index 2cb094d..3c87893 100644 --- a/src/driver/connection/mod.rs +++ b/src/driver/connection/mod.rs @@ -159,7 +159,7 @@ impl Connection { .map_err(|_| Error::IllegalIp)?; let address = IpAddr::from_str(address_str).map_err(|e| { - println!("{:?}", e); + println!("{e:?}"); Error::IllegalIp })?; @@ -335,8 +335,7 @@ fn generate_url(endpoint: &mut String) -> Result { endpoint.truncate(len - 3); } - Url::parse(&format!("wss://{}/?v={}", endpoint, VOICE_GATEWAY_VERSION)) - .or(Err(Error::EndpointUrl)) + Url::parse(&format!("wss://{endpoint}/?v={VOICE_GATEWAY_VERSION}")).or(Err(Error::EndpointUrl)) } #[inline] diff --git a/src/driver/retry/strategy.rs b/src/driver/retry/strategy.rs index 4501728..aa45442 100644 --- a/src/driver/retry/strategy.rs +++ b/src/driver/retry/strategy.rs @@ -59,9 +59,7 @@ impl Default for ExponentialBackoff { impl ExponentialBackoff { pub(crate) fn retry_in(&self, last_wait: Option) -> Duration { let attempt = last_wait.map_or(self.min, |t| 2 * t); - let perturb = (1.0 - (self.jitter * 2.0 * (random::() - 1.0))) - .max(0.0) - .min(2.0); + let perturb = (1.0 - (self.jitter * 2.0 * (random::() - 1.0))).clamp(0.0, 2.0); let mut target_time = attempt.mul_f32(perturb); // Now clamp target time into given range. @@ -71,13 +69,7 @@ impl ExponentialBackoff { self.max }; - if target_time > safe_max { - target_time = safe_max; - } - - if target_time < self.min { - target_time = self.min; - } + target_time = target_time.clamp(self.min, safe_max); target_time } diff --git a/src/input/adapters/async_adapter.rs b/src/input/adapters/async_adapter.rs index 8388470..fe763ac 100644 --- a/src/input/adapters/async_adapter.rs +++ b/src/input/adapters/async_adapter.rs @@ -234,7 +234,7 @@ impl Read for AsyncAdapterStream { std::thread::yield_now(); }, a => { - println!("Misc err {:?}", a); + println!("Misc err {a:?}"); return a; }, } diff --git a/src/input/adapters/cached/error.rs b/src/input/adapters/cached/error.rs index 4cc63bb..ac9ddc5 100644 --- a/src/input/adapters/cached/error.rs +++ b/src/input/adapters/cached/error.rs @@ -27,10 +27,10 @@ pub enum Error { impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { match self { - Self::Create(c) => f.write_fmt(format_args!("failed to create audio stream: {}", c)), + Self::Create(c) => f.write_fmt(format_args!("failed to create audio stream: {c}")), Self::CreatePanicked => f.write_str("sync thread panicked while creating stream"), Self::Streamcatcher(s) => - f.write_fmt(format_args!("illegal streamcatcher config: {}", s)), + f.write_fmt(format_args!("illegal streamcatcher config: {s}")), Self::StreamNotAtStart => f.write_str("stream cannot have been pre-read/parsed, missing headers"), } @@ -87,9 +87,9 @@ pub enum CodecCacheError { impl Display for CodecCacheError { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { match self { - Self::Create(c) => f.write_fmt(format_args!("failed to create audio stream: {}", c)), - Self::Parse(p) => f.write_fmt(format_args!("failed to parse audio format: {}", p)), - Self::Opus(o) => f.write_fmt(format_args!("failed to create Opus encoder: {}", o)), + Self::Create(c) => f.write_fmt(format_args!("failed to create audio stream: {c}")), + Self::Parse(p) => f.write_fmt(format_args!("failed to parse audio format: {p}")), + Self::Opus(o) => f.write_fmt(format_args!("failed to create Opus encoder: {o}")), Self::MetadataEncoding(m) => f.write_fmt(format_args!( "failed to convert track metadata to JSON: {}", m @@ -99,7 +99,7 @@ impl Display for CodecCacheError { Self::UnknownChannelCount => f.write_str("audio stream's channel count could not be determined"), Self::Streamcatcher(s) => - f.write_fmt(format_args!("illegal streamcatcher config: {}", s)), + f.write_fmt(format_args!("illegal streamcatcher config: {s}")), Self::StreamNotAtStart => f.write_str("stream cannot have been pre-read/parsed, missing headers"), } diff --git a/src/input/error.rs b/src/input/error.rs index 7072584..7c91e81 100644 --- a/src/input/error.rs +++ b/src/input/error.rs @@ -25,7 +25,7 @@ impl Display for AudioStreamError { f.write_str("failed to create audio: ")?; match self { Self::RetryIn(t) => f.write_fmt(format_args!("retry in {:.2}s", t.as_secs_f32())), - Self::Fail(why) => f.write_fmt(format_args!("{}", why)), + Self::Fail(why) => f.write_fmt(format_args!("{why}")), Self::Unsupported => f.write_str("operation was not supported"), } } @@ -150,8 +150,7 @@ impl Display for AuxMetadataError { f.write_str("failed to get aux_metadata: ")?; match self { Self::NoCompose => f.write_str("the input has no Compose object"), - Self::Retrieve(e) => - f.write_fmt(format_args!("aux_metadata error from Compose: {}", e)), + Self::Retrieve(e) => f.write_fmt(format_args!("aux_metadata error from Compose: {e}")), } } } diff --git a/src/input/sources/http.rs b/src/input/sources/http.rs index f956129..e03a323 100644 --- a/src/input/sources/http.rs +++ b/src/input/sources/http.rs @@ -66,7 +66,7 @@ impl HttpRequest { match (offset, self.content_length) { (Some(offset), None) => { - resp = resp.header(RANGE, format!("bytes={}-", offset)); + resp = resp.header(RANGE, format!("bytes={offset}-")); }, (offset, Some(max)) => { resp = resp.header( diff --git a/src/tracks/command.rs b/src/tracks/command.rs index 0c3a17f..f09f5a1 100644 --- a/src/tracks/command.rs +++ b/src/tracks/command.rs @@ -46,12 +46,12 @@ impl Debug for TrackCommand { Self::Play => "Play".to_string(), Self::Pause => "Pause".to_string(), Self::Stop => "Stop".to_string(), - Self::Volume(vol) => format!("Volume({})", vol), + Self::Volume(vol) => format!("Volume({vol})"), Self::Seek(s) => format!("Seek({:?})", s.time), - Self::AddEvent(evt) => format!("AddEvent({:?})", evt), + Self::AddEvent(evt) => format!("AddEvent({evt:?})"), Self::Do(_f) => "Do([function])".to_string(), - Self::Request(tx) => format!("Request({:?})", tx), - Self::Loop(loops) => format!("Loop({:?})", loops), + Self::Request(tx) => format!("Request({tx:?})"), + Self::Loop(loops) => format!("Loop({loops:?})"), Self::MakePlayable(_) => "MakePlayable".to_string(), } ) diff --git a/src/tracks/error.rs b/src/tracks/error.rs index 18e3eaa..0cec155 100644 --- a/src/tracks/error.rs +++ b/src/tracks/error.rs @@ -37,7 +37,7 @@ impl Display for ControlError { write!(f, "given event listener can't be fired on a track") }, ControlError::Play(p) => { - write!(f, "i/o request on track failed: {}", p) + write!(f, "i/o request on track failed: {p}") }, ControlError::Dropped => write!(f, "request was replaced by another of same type"), }