about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-17 18:52:12 +0300
committerVika <vika@fireburn.ru>2021-05-17 18:52:12 +0300
commitd178e35c34a9106dd6c0a86286ff56dc8b297942 (patch)
treedb99416312044e76a7678d836dc635bf0cf888b1
parent9a2791d745f4a9f0307eb69b50de5629f51564cc (diff)
Make clippy happy
-rw-r--r--src/database/redis/mod.rs20
-rw-r--r--src/frontend/mod.rs32
-rw-r--r--src/indieauth.rs2
-rw-r--r--src/micropub/post.rs12
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<serde_json::Value>| {
-                            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::<Vec<_>>())
     }
 
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::<Vec<_>>().get(1) {
-            if let Some(part) = part.split(";").next() {
-                let mut parts = part.split(",");
+        if let Some(part) = uri.split(':').collect::<Vec<_>>().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<serde_json::Value>>) {
@@ -689,11 +688,11 @@ pub async fn onboarding_receiver<S: Storage>(mut req: Request<ApplicationState<S
     #[cfg(all(debug_assertions, not(test)))]
     let me = url::Url::parse("http://localhost:8080/").unwrap();
 
-    if let Ok(_) = get_post_from_database(backend, me.as_str(), None, &None).await {
-        Err(FrontendError::with_code(
+    if get_post_from_database(backend, me.as_str(), None, &None).await.is_ok() {
+        return Err(FrontendError::with_code(
             StatusCode::Forbidden,
             "Onboarding is over. Are you trying to take over somebody's website?!",
-        ))?
+        ).into())
     }
     info!("Onboarding new user: {}", me);
 
@@ -704,10 +703,10 @@ pub async fn onboarding_receiver<S: Storage>(mut req: Request<ApplicationState<S
         .await?;
 
     if body.user["type"][0] != "h-card" || body.first_post["type"][0] != "h-entry" {
-        Err(FrontendError::with_code(
+        return Err(FrontendError::with_code(
             StatusCode::BadRequest,
             "user and first_post should be h-card and h-entry",
-        ))?
+        ).into())
     }
     info!("Validated body.user and body.first_post as microformats2");
 
@@ -748,8 +747,7 @@ pub async fn coffee<S: Storage>(_: Request<ApplicationState<S>>) -> 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<S: Storage>(req: Request<ApplicationState<S>>) -> Result {
@@ -796,7 +794,7 @@ pub async fn mainpage<S: Storage>(req: Request<ApplicationState<S>>) -> 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<S: Storage>(req: Request<ApplicationState<S>>) -> 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<S: Storage>(
             .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<S: Storage>(
     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::<Vec<_>>()