From c5d11f220e06f0d4f99a729e5320054f8f8123aa Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 26 Dec 2023 18:27:25 -0500 Subject: [PATCH] Fix clippy warnings --- src/client.rs | 6 +++--- src/instance_info.rs | 2 +- src/main.rs | 7 +++---- src/server.rs | 8 -------- src/utils.rs | 36 +++++++++++++++++------------------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/client.rs b/src/client.rs index cc704d6..451893d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -49,14 +49,14 @@ pub async fn canonical_path(path: String) -> Result, String> { let status = res.status().as_u16(); match status { - 429 => return Err("Too many requests.".to_string()), + 429 => Err("Too many requests.".to_string()), // If Reddit responds with a 2xx, then the path is already canonical. - 200..=299 => return Ok(Some(path)), + 200..=299 => Ok(Some(path)), // If Reddit responds with anything other than 3xx (except for the 2xx as // above), return a None. - 300..=399 => return Ok(None), + 300..=399 => Ok(None), _ => Ok( res diff --git a/src/instance_info.rs b/src/instance_info.rs index e1473ad..85e198d 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -21,7 +21,7 @@ pub(crate) static INSTANCE_INFO: Lazy = Lazy::new(InstanceInfo::ne pub async fn instance_info(req: Request) -> Result, String> { // This will retrieve the extension given, or create a new string - which will // simply become the last option, an HTML page. - let extension = req.param("extension").unwrap_or(String::new()); + let extension = req.param("extension").unwrap_or_default(); let response = match extension.as_str() { "yaml" | "yml" => info_yaml(), "txt" => info_txt(), diff --git a/src/main.rs b/src/main.rs index 8a24fbe..fc4069b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -325,14 +325,13 @@ async fn main() { // Instance info page app.at("/info").get(|r| instance_info::instance_info(r).boxed()); app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed()); - - // Handle obfuscated share links. + + // Handle obfuscated share links. // Note that this still forces the server to follow the share link to get to the post, so maybe this wants to be updated with a warning before it follow it app.at("/r/:sub/s/:id").get(|req: Request| { Box::pin(async move { let sub = req.param("sub").unwrap_or_default(); match req.param("id").as_deref() { - // Share link Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await { Ok(Some(path)) => Ok(redirect(path.split('?').next().unwrap_or_default().to_string())), @@ -345,7 +344,7 @@ async fn main() { } }) }); - + app.at("/:id").get(|req: Request| { Box::pin(async move { match req.param("id").as_deref() { diff --git a/src/server.rs b/src/server.rs index f376f33..00f87c7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -353,14 +353,6 @@ fn determine_compressor(accept_encoding: String) -> Option { impl PartialOrd for CompressorCandidate { fn partial_cmp(&self, other: &Self) -> Option { - // Guard against NAN, both on our end and on the other. - if self.q.is_nan() || other.q.is_nan() { - return None; - }; - - // f64 and CompressionType are ordered, except in the case - // where the f64 is NAN (which we checked against), so we - // can safely return a Some here. Some(self.cmp(other)) } } diff --git a/src/utils.rs b/src/utils.rs index 1b052ba..d0e0249 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -604,23 +604,23 @@ impl Preferences { } Self { available_themes: themes, - theme: setting(&req, "theme"), - front_page: setting(&req, "front_page"), - layout: setting(&req, "layout"), - wide: setting(&req, "wide"), - show_nsfw: setting(&req, "show_nsfw"), - blur_nsfw: setting(&req, "blur_nsfw"), - use_hls: setting(&req, "use_hls"), - hide_hls_notification: setting(&req, "hide_hls_notification"), - autoplay_videos: setting(&req, "autoplay_videos"), - fixed_navbar: setting_or_default(&req, "fixed_navbar", "on".to_string()), + theme: setting(req, "theme"), + front_page: setting(req, "front_page"), + layout: setting(req, "layout"), + wide: setting(req, "wide"), + show_nsfw: setting(req, "show_nsfw"), + blur_nsfw: setting(req, "blur_nsfw"), + use_hls: setting(req, "use_hls"), + hide_hls_notification: setting(req, "hide_hls_notification"), + autoplay_videos: setting(req, "autoplay_videos"), + fixed_navbar: setting_or_default(req, "fixed_navbar", "on".to_string()), disable_visit_reddit_confirmation: setting(req, "disable_visit_reddit_confirmation"), - comment_sort: setting(&req, "comment_sort"), - post_sort: setting(&req, "post_sort"), - subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), - filters: setting(&req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), - hide_awards: setting(&req, "hide_awards"), - hide_score: setting(&req, "hide_score"), + comment_sort: setting(req, "comment_sort"), + post_sort: setting(req, "post_sort"), + subscriptions: setting(req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + filters: setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + hide_awards: setting(req, "hide_awards"), + hide_score: setting(req, "hide_score"), } } } @@ -1074,9 +1074,7 @@ mod tests { #[test] fn rewrite_urls_keeps_intentional_backslashes() { assert_eq!( - rewrite_urls( - "printf \"\\npolkit.addRule(function(action, subject)" - ), + rewrite_urls("printf \"\\npolkit.addRule(function(action, subject)"), "printf \"\\npolkit.addRule(function(action, subject)" ); }