From d178e35c34a9106dd6c0a86286ff56dc8b297942 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 17 May 2021 18:52:12 +0300 Subject: Make clippy happy --- src/database/redis/mod.rs | 20 ++++++++------------ src/frontend/mod.rs | 32 +++++++++++++++----------------- src/indieauth.rs | 2 +- src/micropub/post.rs | 12 ++++++------ 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/database/redis/mod.rs b/src/database/redis/mod.rs index 5a6b70d..cf94386 100644 --- a/src/database/redis/mod.rs +++ b/src/database/redis/mod.rs @@ -165,17 +165,13 @@ impl Storage for RedisStorage { .map(|channel| { self.get_post(channel).map(|result| result.unwrap()).map( |post: Option| { - if let Some(post) = post { - Some(MicropubChannel { - uid: post["properties"]["uid"][0].as_str().unwrap().to_string(), - name: post["properties"]["name"][0] - .as_str() - .unwrap() - .to_string(), - }) - } else { - None - } + post.map(|post| MicropubChannel { + uid: post["properties"]["uid"][0].as_str().unwrap().to_string(), + name: post["properties"]["name"][0] + .as_str() + .unwrap() + .to_string(), + }) }, ) }) @@ -183,7 +179,7 @@ impl Storage for RedisStorage { ) .await .into_iter() - .filter_map(|chan| chan) + .flatten() .collect::>()) } diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index eefc257..029c5dc 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -8,25 +8,24 @@ static POSTS_PER_PAGE: usize = 20; mod templates { use super::IndiewebEndpoints; - use chrono; use ellipse::Ellipse; use http_types::StatusCode; use log::error; /// Return a pretty location specifier from a geo: URI. fn decode_geo_uri(uri: &str) -> String { - if let Some(part) = uri.split(":").collect::>().get(1) { - if let Some(part) = part.split(";").next() { - let mut parts = part.split(","); + if let Some(part) = uri.split(':').collect::>().get(1) { + if let Some(part) = part.split(';').next() { + let mut parts = part.split(','); let lat = parts.next().unwrap(); let lon = parts.next().unwrap(); // TODO - format them as proper latitude and longitude return format!("{}, {}", lat, lon); } else { - return uri.to_string(); + uri.to_string() } } else { - return uri.to_string(); + uri.to_string() } } @@ -379,7 +378,7 @@ mod templates { @markup::raw(post["properties"]["content"][0]["html"].as_str().unwrap().trim()) } } - @WebInteractions { post: post } + @WebInteractions { post } } } PhotoGallery<'a>(photos: Option<&'a Vec>) { @@ -689,11 +688,11 @@ pub async fn onboarding_receiver(mut req: Request(mut req: Request(_: Request>) -> Result { Err(FrontendError::with_code( StatusCode::ImATeapot, "Someone asked this website to brew them some coffee...", - ))?; - return Ok(Response::builder(500).build()); // unreachable + ).into()) } pub async fn mainpage(req: Request>) -> Result { @@ -796,7 +794,7 @@ pub async fn mainpage(req: Request>) -> Result { ) .build()) } else { - Err(feed_err)? + return Err(feed_err.into()) } } else { Ok(Response::builder(200) @@ -850,10 +848,10 @@ pub async fn render_post(req: Request>) -> Resul "h-entry" => templates::Entry { post: &post }.to_string(), "h-card" => templates::VCard { card: &post }.to_string(), "h-feed" => templates::Feed { feed: &post }.to_string(), - _ => Err(FrontendError::with_code( + _ => return Err(FrontendError::with_code( StatusCode::InternalServerError, "Couldn't render an unknown type", - ))?, + ).into()), }; Ok(Response::builder(200) diff --git a/src/indieauth.rs b/src/indieauth.rs index f6bac04..7a2a07e 100644 --- a/src/indieauth.rs +++ b/src/indieauth.rs @@ -126,7 +126,7 @@ impl Drop for IndieAuthMiddleware { // Because apparently you can't run async code from Drop... // This should drop the last reference for the [`cache`], // allowing it to be dropped. - async_std::task::spawn(async move { task.cancel() }); + async_std::task::spawn(async move { task.cancel().await }); } } #[async_trait] diff --git a/src/micropub/post.rs b/src/micropub/post.rs index b3fe4ee..edadeed 100644 --- a/src/micropub/post.rs +++ b/src/micropub/post.rs @@ -346,19 +346,19 @@ async fn post_process_new_post( .filter_map(|v: surf::Url| async move { if let Ok(res) = http.get(&v).send().await { if res.status() != 200 { - return None; + None } else { - return Some((v, res)); + Some((v, res)) } } else { - return None; + None } }) .filter_map(|(v, mut res): (surf::Url, surf::Response)| async move { if let Ok(body) = res.body_string().await { - return Some((v, body)); + Some((v, body)) } else { - return None; + None } }) .collect() @@ -373,7 +373,7 @@ async fn post_process_new_post( if let Some(syndication_targets) = post["properties"]["syndicate-to"].as_array() { syndicated_copies = stream::iter( syndication_targets - .into_iter() + .iter() .filter_map(|v| v.as_str()) .filter_map(|t| surf::Url::parse(t).ok()) .collect::>() -- cgit 1.4.1