about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika Shleina <vika@fireburn.ru>2021-07-15 04:46:22 +0300
committerVika <vika@fireburn.ru>2021-07-19 04:57:11 +0300
commitdc490adb60db3d560e54cafe28ebf1f8ba1731b6 (patch)
tree8806c22c711e41cb478df2f969da4bdd69d2b9bc
parentd399fd0bd00c9ea073e5b057de70c9ffdd9356f8 (diff)
make clippy happy
-rw-r--r--Cargo.toml15
-rw-r--r--flake.lock6
-rw-r--r--src/bin/kittybox_bulk_import.rs8
-rw-r--r--src/bin/pyindieblog_to_kittybox.rs7
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs1
-rw-r--r--src/micropub/get.rs10
-rw-r--r--src/micropub/post.rs10
8 files changed, 30 insertions, 29 deletions
diff --git a/Cargo.toml b/Cargo.toml
index b07da8a..79f7107 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,23 +42,26 @@ retainer = "^0.2.2"          # Minimal async cache in Rust with support for key
 serde_json = "^1.0.64"       # A JSON serialization file format
 serde_urlencoded = "^0.7.0"  # `x-www-form-urlencoded` meets Serde
 tide = "^0.16.0"             # A minimal and pragmatic Rust web application framework built for rapid development
-[dependencies.async-std]    # Async version of the Rust standard library
+[dependencies.anyhow]
+version = "^1.0.42"
+optional = true
+[dependencies.async-std]     # Async version of the Rust standard library
 version = "^1.9.0"
 features = ["attributes"]
-[dependencies.chrono]       # Date and time library for Rust
+[dependencies.chrono]        # Date and time library for Rust
 version = "^0.4.19"
 features = ["serde"]
-[dependencies.mobc-redis]   # Redis support for the mobc connection pool
+[dependencies.mobc-redis]    # Redis support for the mobc connection pool
 version = "^0.7.0"
 features = ["async-std-comp"]
 default-features = false
-[dependencies.serde]        # A generic serialization/deserialization framework
+[dependencies.serde]         # A generic serialization/deserialization framework
 version = "^1.0.125"
 features = ["derive"]
-[dependencies.surf]         # Surf the web - HTTP client framework
+[dependencies.surf]          # Surf the web - HTTP client framework
 version = "^2.2.0"
 default-features = false
 features = ["h1-client-rustls", "encoding", "middleware-logger"]
-[dependencies.url]          # URL library for Rust, based on the WHATWG URL Standard
+[dependencies.url]           # URL library for Rust, based on the WHATWG URL Standard
 version = "^2.2.1"
 features = ["serde"]
diff --git a/flake.lock b/flake.lock
index b87cc53..79105d0 100644
--- a/flake.lock
+++ b/flake.lock
@@ -38,11 +38,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1623312136,
-        "narHash": "sha256-zPedrdLS5W+jATD7sybbNhET7IHEfgdlb0T4uJjSdFM=",
+        "lastModified": 1626282673,
+        "narHash": "sha256-tPmKacGmININsdsOeeHY7xsAPXWPLiSZlSNHJnTTCRY=",
         "owner": "kisik21",
         "repo": "nixpkgs",
-        "rev": "15d6d10e2cec42cd46edb4a230647fc59b4e0e95",
+        "rev": "28ab753837babd73e2200fb76a6c40f6cb8aee28",
         "type": "github"
       },
       "original": {
diff --git a/src/bin/kittybox_bulk_import.rs b/src/bin/kittybox_bulk_import.rs
index 652a4c2..a5252b7 100644
--- a/src/bin/kittybox_bulk_import.rs
+++ b/src/bin/kittybox_bulk_import.rs
@@ -1,4 +1,4 @@
-use std::io::{self, Read};
+use std::io;
 use std::fs::File;
 use anyhow::{anyhow, Context, Result, bail};
 
@@ -24,10 +24,10 @@ async fn main() -> Result<()> {
     let url = surf::Url::parse(&args[1])?;
     let client = surf::Client::new();
 
-    let mut iter = data.into_iter();
+    let iter = data.into_iter();
 
-    while let Some(post) = iter.next() {
-        println!("Processing {}...", post["properties"]["url"][0].as_str().or(post["properties"]["published"][0].as_str().or(post["properties"]["name"][0].as_str().or(Some("<unidentified post>")))).unwrap());
+    for post in iter {
+        println!("Processing {}...", post["properties"]["url"][0].as_str().or_else(|| post["properties"]["published"][0].as_str().or_else(|| post["properties"]["name"][0].as_str().or(Some("<unidentified post>")))).unwrap());
         match client.post(&url)
             .body(surf::http::Body::from_string(
                 serde_json::to_string(&post)?))
diff --git a/src/bin/pyindieblog_to_kittybox.rs b/src/bin/pyindieblog_to_kittybox.rs
index 7935da5..c932e0a 100644
--- a/src/bin/pyindieblog_to_kittybox.rs
+++ b/src/bin/pyindieblog_to_kittybox.rs
@@ -1,10 +1,9 @@
 use std::collections::HashMap;
 use std::fs::File;
-use anyhow::{Error, Result, Context, anyhow, bail};
+use anyhow::{Result, Context, anyhow};
 use mobc_redis::redis;
 use mobc_redis::redis::AsyncCommands;
 use serde::{Serialize, Deserialize};
-use serde_json::json;
 
 #[derive(Default, Serialize, Deserialize)]
 struct PyindieblogData {
@@ -16,10 +15,10 @@ struct PyindieblogData {
 async fn main() -> Result<()> {
     let mut args = std::env::args();
     args.next(); // skip argv[0] which is the name
-    let redis_uri = args.next().ok_or(anyhow!("No Redis URI provided"))?;
+    let redis_uri = args.next().ok_or_else(|| anyhow!("No Redis URI provided"))?;
     let client = redis::Client::open(redis_uri.as_str()).with_context(|| format!("Failed to construct Redis client on {}", redis_uri))?;
 
-    let filename = args.next().ok_or(anyhow!("No filename provided for export"))?;
+    let filename = args.next().ok_or_else(|| anyhow!("No filename provided for export"))?;
 
     let mut data: Vec<serde_json::Value>;
 
diff --git a/src/lib.rs b/src/lib.rs
index d1bff68..91dd340 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -94,7 +94,7 @@ pub async fn get_app_with_test_redis(
         storage: backend.clone(),
         http_client: surf::Client::new(),
     });
-    return (redis_instance, backend, equip_app(app));
+    (redis_instance, backend, equip_app(app))
 }
 
 #[cfg(test)]
diff --git a/src/main.rs b/src/main.rs
index 23b5ddb..2f7152f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-use kittybox;
 use log::{debug, error, info};
 use std::env;
 use surf::Url;
diff --git a/src/micropub/get.rs b/src/micropub/get.rs
index 525bf12..5db99f7 100644
--- a/src/micropub/get.rs
+++ b/src/micropub/get.rs
@@ -40,21 +40,21 @@ where
                 Ok(chans) => channels = chans,
                 Err(err) => return Ok(err.into())
             }
-            return Ok(Response::builder(200).body(json!(channels)).build())
+            Ok(Response::builder(200).body(json!(channels)).build())
         }
         "source" => {
             if user.check_scope("create") || user.check_scope("update") || user.check_scope("delete") || user.check_scope("undelete") {
                 if let Some(url) = query.url {
                     match backend.get_post(&url).await {
                         Ok(post) => if let Some(post) = post {
-                            return Ok(Response::builder(200).body(post).build())
+                            Ok(Response::builder(200).body(post).build())
                         } else {
-                            return Ok(Response::builder(404).build())
+                            Ok(Response::builder(404).build())
                         },
-                        Err(err) => return Ok(err.into())
+                        Err(err) => Ok(err.into())
                     }
                 } else {
-                    return Ok(Response::builder(400).body(json!({
+                    Ok(Response::builder(400).body(json!({
                         "error": "invalid_request",
                         "error_description": "Please provide `url`."
                     })).build())
diff --git a/src/micropub/post.rs b/src/micropub/post.rs
index edadeed..639346b 100644
--- a/src/micropub/post.rs
+++ b/src/micropub/post.rs
@@ -271,10 +271,10 @@ pub async fn new_post<S: Storage>(
     // do background processing on the post
     async_std::task::spawn(post_process_new_post(req, post));
 
-    return Ok(Response::builder(202)
+    Ok(Response::builder(202)
         .header("Location", &uid)
         .body(json!({"status": "accepted", "location": &uid}))
-        .build());
+        .build())
 }
 
 async fn create_feed(
@@ -519,7 +519,7 @@ async fn process_json<S: Storage>(
                 if let Err(error) = req.state().storage.delete_post(&url).await {
                     return Ok(error.into());
                 }
-                return Ok(Response::builder(200).build());
+                Ok(Response::builder(200).build())
             }
             "update" => {
                 if !user.check_scope("update") {
@@ -530,9 +530,9 @@ async fn process_json<S: Storage>(
                     );
                 }
                 if let Err(error) = req.state().storage.update_post(&url, body.clone()).await {
-                    return Ok(error.into());
+                    Ok(error.into())
                 } else {
-                    return Ok(Response::builder(204).build());
+                    Ok(Response::builder(204).build())
                 }
             }
             _ => return error_json!(400, "invalid_request", "This action is not supported."),