From 8f1c0a85cfdc718400ce86490e796f47aa3683a3 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 3 Apr 2020 16:14:30 +0900 Subject: [PATCH 1/2] Fix/suppress warnings --- async_db/src/db.rs | 2 -- async_db/src/main.rs | 1 + async_ex2/src/handlers/parts.rs | 8 ++++---- async_ex2/src/handlers/products.rs | 8 ++++---- async_pg/src/main.rs | 2 +- awc_https/src/main.rs | 2 +- docker_sample/src/main.rs | 2 +- graphql-demo/src/db.rs | 1 - graphql-demo/src/schemas/product.rs | 1 - graphql-demo/src/schemas/root.rs | 13 ++++++------- graphql-demo/src/schemas/user.rs | 7 +++---- jsonrpc/src/main.rs | 4 +++- middleware/src/main.rs | 2 ++ r2d2/src/main.rs | 1 - server-sent-events/src/main.rs | 1 - shutdown-server/src/main.rs | 2 +- state/src/main.rs | 1 + todo/src/api.rs | 2 +- todo/src/model.rs | 1 - 19 files changed, 29 insertions(+), 32 deletions(-) diff --git a/async_db/src/db.rs b/async_db/src/db.rs index 252f55cb..d7c76923 100644 --- a/async_db/src/db.rs +++ b/async_db/src/db.rs @@ -1,8 +1,6 @@ use actix_web::{web, Error as AWError}; use failure::Error; use futures::{Future, TryFutureExt}; -use r2d2; -use r2d2_sqlite; use rusqlite::{Statement, NO_PARAMS}; use serde::{Deserialize, Serialize}; use std::{thread::sleep, time::Duration}; diff --git a/async_db/src/main.rs b/async_db/src/main.rs index 90a59562..66f368fc 100644 --- a/async_db/src/main.rs +++ b/async_db/src/main.rs @@ -22,6 +22,7 @@ mod db; use db::{Pool, Queries}; /// Version 1: Calls 4 queries in sequential order, as an asynchronous handler +#[allow(clippy::eval_order_dependence)] // it's FP? async fn asyncio_weather(db: web::Data) -> Result { let result = vec![ db::execute(&db, Queries::GetTopTenHottestYears).await?, diff --git a/async_ex2/src/handlers/parts.rs b/async_ex2/src/handlers/parts.rs index 9e8725b4..734931af 100644 --- a/async_ex2/src/handlers/parts.rs +++ b/async_ex2/src/handlers/parts.rs @@ -2,18 +2,18 @@ use actix_web::{web, Error, HttpResponse}; use crate::common::{Part, Product}; -pub async fn get_parts(query: web::Query>) -> Result { +pub async fn get_parts(_query: web::Query>) -> Result { Ok(HttpResponse::Ok().finish()) } -pub async fn add_part(new_part: web::Json) -> Result { +pub async fn add_part(_new_part: web::Json) -> Result { Ok(HttpResponse::Ok().finish()) } -pub async fn get_part_detail(id: web::Path) -> Result { +pub async fn get_part_detail(_id: web::Path) -> Result { Ok(HttpResponse::Ok().finish()) } -pub async fn remove_part(id: web::Path) -> Result { +pub async fn remove_part(_id: web::Path) -> Result { Ok(HttpResponse::Ok().finish()) } diff --git a/async_ex2/src/handlers/products.rs b/async_ex2/src/handlers/products.rs index 624b8209..7f65fd61 100644 --- a/async_ex2/src/handlers/products.rs +++ b/async_ex2/src/handlers/products.rs @@ -3,22 +3,22 @@ use actix_web::{web, Error, HttpResponse}; use crate::common::{Part, Product}; pub async fn get_products( - query: web::Query>, + _query: web::Query>, ) -> Result { Ok(HttpResponse::Ok().finish()) } pub async fn add_product( - new_product: web::Json, + _new_product: web::Json, ) -> Result { Ok(HttpResponse::Ok().finish()) } -pub async fn get_product_detail(id: web::Path) -> Result { +pub async fn get_product_detail(_id: web::Path) -> Result { Ok(HttpResponse::Ok().finish()) } -pub async fn remove_product(id: web::Path) -> Result { +pub async fn remove_product(_id: web::Path) -> Result { Ok(HttpResponse::Ok().finish()) } diff --git a/async_pg/src/main.rs b/async_pg/src/main.rs index 8d48c682..ad3dc989 100644 --- a/async_pg/src/main.rs +++ b/async_pg/src/main.rs @@ -99,7 +99,7 @@ mod handlers { let user_info: User = user.into_inner(); let client: Client = - db_pool.get().await.map_err(|err| MyError::PoolError(err))?; + db_pool.get().await.map_err(MyError::PoolError)?; let new_user = db::add_user(&client, user_info).await?; diff --git a/awc_https/src/main.rs b/awc_https/src/main.rs index 7415c947..2958ea9c 100644 --- a/awc_https/src/main.rs +++ b/awc_https/src/main.rs @@ -2,7 +2,7 @@ use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, client::{Client use openssl::ssl::{SslConnector, SslMethod}; -async fn index(req: HttpRequest) -> HttpResponse { +async fn index(_req: HttpRequest) -> HttpResponse { let builder = SslConnector::builder(SslMethod::tls()).unwrap(); let client = Client::build() diff --git a/docker_sample/src/main.rs b/docker_sample/src/main.rs index 803e0b6b..af38893d 100644 --- a/docker_sample/src/main.rs +++ b/docker_sample/src/main.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate actix_web; -use actix_web::{web, App, HttpResponse, HttpServer, Responder}; +use actix_web::{App, HttpResponse, HttpServer, Responder}; #[get("/")] async fn index() -> impl Responder { diff --git a/graphql-demo/src/db.rs b/graphql-demo/src/db.rs index 7924fce8..e0983dd6 100644 --- a/graphql-demo/src/db.rs +++ b/graphql-demo/src/db.rs @@ -1,4 +1,3 @@ -use r2d2; use r2d2_mysql::mysql::{Opts, OptsBuilder}; use r2d2_mysql::MysqlConnectionManager; diff --git a/graphql-demo/src/schemas/product.rs b/graphql-demo/src/schemas/product.rs index 0fe3744f..9304ff36 100644 --- a/graphql-demo/src/schemas/product.rs +++ b/graphql-demo/src/schemas/product.rs @@ -1,4 +1,3 @@ -use juniper; use mysql::{from_row, params, Error as DBError, Row}; use crate::schemas::root::Context; diff --git a/graphql-demo/src/schemas/root.rs b/graphql-demo/src/schemas/root.rs index ad3e890a..051ef496 100644 --- a/graphql-demo/src/schemas/root.rs +++ b/graphql-demo/src/schemas/root.rs @@ -1,4 +1,3 @@ -use juniper; use juniper::{FieldError, FieldResult, RootNode}; use mysql::{from_row, params, Error as DBError, Row}; @@ -109,9 +108,9 @@ impl MutationRoot { let insert: Result, DBError> = conn.first_exec( "INSERT INTO user(id, name, email) VALUES(:id, :name, :email)", params! { - "id" => &new_id.to_owned(), - "name" => &user.name.to_owned(), - "email" => &user.email.to_owned(), + "id" => &new_id, + "name" => &user.name, + "email" => &user.email, }, ); @@ -141,9 +140,9 @@ impl MutationRoot { let insert: Result, DBError> = conn.first_exec( "INSERT INTO product(id, user_id, name, price) VALUES(:id, :user_id, :name, :price)", params! { - "id" => &new_id.to_owned(), - "user_id" => &product.user_id.to_owned(), - "name" => &product.name.to_owned(), + "id" => &new_id, + "user_id" => &product.user_id, + "name" => &product.name, "price" => &product.price.to_owned(), }, ); diff --git a/graphql-demo/src/schemas/user.rs b/graphql-demo/src/schemas/user.rs index 4d71ae86..69ed3dc5 100644 --- a/graphql-demo/src/schemas/user.rs +++ b/graphql-demo/src/schemas/user.rs @@ -1,4 +1,3 @@ -use juniper; use mysql::{from_row, params}; use crate::schemas::product::Product; @@ -33,7 +32,8 @@ impl User { fn products(&self, context: &Context) -> Vec { let mut conn = context.dbpool.get().unwrap(); - let products = conn + + conn .prep_exec( "select * from product where user_id=:user_id", params! { @@ -54,7 +54,6 @@ impl User { }) .collect() }) - .unwrap(); - products + .unwrap() } } diff --git a/jsonrpc/src/main.rs b/jsonrpc/src/main.rs index da0f1db2..c2c5644e 100644 --- a/jsonrpc/src/main.rs +++ b/jsonrpc/src/main.rs @@ -1,3 +1,6 @@ +// Allow this lint since it's fine to use type directly in the short example. +#![allow(clippy::type_complexity)] + use std::error; use std::pin::Pin; use std::sync::{Arc, RwLock}; @@ -7,7 +10,6 @@ use actix_rt::time::delay_for; use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; use bytes::Bytes; use futures::{Future, FutureExt}; -use serde_json; use serde_json::Value; #[allow(dead_code)] diff --git a/middleware/src/main.rs b/middleware/src/main.rs index c2237beb..de3a1b70 100644 --- a/middleware/src/main.rs +++ b/middleware/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::type_complexity)] + use actix_service::Service; use actix_web::{web, App, HttpServer}; use futures::future::FutureExt; diff --git a/r2d2/src/main.rs b/r2d2/src/main.rs index 25e89aef..4cbbb24a 100644 --- a/r2d2/src/main.rs +++ b/r2d2/src/main.rs @@ -4,7 +4,6 @@ use std::io; use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; -use uuid; /// Async request handler. Ddb pool is stored in application state. async fn index( diff --git a/server-sent-events/src/main.rs b/server-sent-events/src/main.rs index bbfc51dc..3c3d8586 100644 --- a/server-sent-events/src/main.rs +++ b/server-sent-events/src/main.rs @@ -5,7 +5,6 @@ use std::time::Duration; use actix_web::web::{Bytes, Data, Path}; use actix_web::{web, App, Error, HttpResponse, HttpServer, Responder}; -use env_logger; use futures::{Stream, StreamExt}; use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::time::{interval_at, Instant}; diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index b051a57b..6356c206 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -23,7 +23,7 @@ async fn main() -> std::io::Result<()> { // create a channel let (tx, rx) = mpsc::channel::<()>(); - let stopper = tx.clone(); + let _stopper = tx.clone(); let bind = "127.0.0.1:8080"; diff --git a/state/src/main.rs b/state/src/main.rs index 29b9a9d9..cad3a576 100644 --- a/state/src/main.rs +++ b/state/src/main.rs @@ -54,6 +54,7 @@ async fn main() -> io::Result<()> { env_logger::init(); // Create some global state prior to building the server + #[allow(clippy::mutex_atomic)] // it's intentional. let counter1 = web::Data::new(Mutex::new(0usize)); let counter3 = web::Data::new(AtomicUsize::new(0usize)); diff --git a/todo/src/api.rs b/todo/src/api.rs index 344fbb43..f70e06fe 100644 --- a/todo/src/api.rs +++ b/todo/src/api.rs @@ -27,7 +27,7 @@ pub async fn index( let rendered = tmpl .render("index.html.tera", &context) - .map_err(|e| error::ErrorInternalServerError(e))?; + .map_err(error::ErrorInternalServerError)?; Ok(HttpResponse::Ok().body(rendered)) } diff --git a/todo/src/model.rs b/todo/src/model.rs index 2c8c03a6..6fa1dc2e 100644 --- a/todo/src/model.rs +++ b/todo/src/model.rs @@ -1,4 +1,3 @@ -use diesel; use diesel::pg::PgConnection; use diesel::prelude::*; use serde::Serialize; From 046604f286edf73a47c20e68dbe3a803e8409c03 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 3 Apr 2020 16:16:17 +0900 Subject: [PATCH 2/2] Run rustfmt --- async_pg/src/main.rs | 3 +-- awc_https/src/main.rs | 30 +++++++++++----------- docker_sample/src/main.rs | 14 ++++------- graphql-demo/src/schemas/user.rs | 43 ++++++++++++++++---------------- shutdown-server/src/main.rs | 1 - 5 files changed, 42 insertions(+), 49 deletions(-) diff --git a/async_pg/src/main.rs b/async_pg/src/main.rs index ad3dc989..19f4f211 100644 --- a/async_pg/src/main.rs +++ b/async_pg/src/main.rs @@ -98,8 +98,7 @@ mod handlers { ) -> Result { let user_info: User = user.into_inner(); - let client: Client = - db_pool.get().await.map_err(MyError::PoolError)?; + let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; let new_user = db::add_user(&client, user_info).await?; diff --git a/awc_https/src/main.rs b/awc_https/src/main.rs index 2958ea9c..5b3d1831 100644 --- a/awc_https/src/main.rs +++ b/awc_https/src/main.rs @@ -1,15 +1,17 @@ -use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, client::{Client, Connector}}; +use actix_web::{ + client::{Client, Connector}, + web, App, HttpRequest, HttpResponse, HttpServer, +}; use openssl::ssl::{SslConnector, SslMethod}; - async fn index(_req: HttpRequest) -> HttpResponse { - let builder = SslConnector::builder(SslMethod::tls()).unwrap(); + let builder = SslConnector::builder(SslMethod::tls()).unwrap(); let client = Client::build() .connector(Connector::new().ssl(builder.build()).finish()) .finish(); - let now = std::time::Instant::now(); + let now = std::time::Instant::now(); let payload = client .get("https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg") @@ -21,22 +23,20 @@ async fn index(_req: HttpRequest) -> HttpResponse { .await .unwrap(); - println!("awc time elapsed while reading bytes into memory: {} ms", now.elapsed().as_millis()); + println!( + "awc time elapsed while reading bytes into memory: {} ms", + now.elapsed().as_millis() + ); - HttpResponse::Ok() - .content_type("image/jpeg") - .body(payload) + HttpResponse::Ok().content_type("image/jpeg").body(payload) } #[actix_rt::main] async fn main() -> std::io::Result<()> { let port = 3000; - HttpServer::new(|| { - App::new() - .service(web::resource("/").to(index)) - }) - .bind(("0.0.0.0", port))? - .run() - .await + HttpServer::new(|| App::new().service(web::resource("/").to(index))) + .bind(("0.0.0.0", port))? + .run() + .await } diff --git a/docker_sample/src/main.rs b/docker_sample/src/main.rs index af38893d..22b0371a 100644 --- a/docker_sample/src/main.rs +++ b/docker_sample/src/main.rs @@ -19,12 +19,8 @@ async fn again() -> impl Responder { async fn main() -> std::io::Result<()> { println!("Starting actix-web server"); - HttpServer::new(|| { - App::new() - .service(index) - .service(again) - }) - .bind("0.0.0.0:5000")? - .run() - .await -} \ No newline at end of file + HttpServer::new(|| App::new().service(index).service(again)) + .bind("0.0.0.0:5000")? + .run() + .await +} diff --git a/graphql-demo/src/schemas/user.rs b/graphql-demo/src/schemas/user.rs index 69ed3dc5..d17e2931 100644 --- a/graphql-demo/src/schemas/user.rs +++ b/graphql-demo/src/schemas/user.rs @@ -33,27 +33,26 @@ impl User { fn products(&self, context: &Context) -> Vec { let mut conn = context.dbpool.get().unwrap(); - conn - .prep_exec( - "select * from product where user_id=:user_id", - params! { - "user_id" => &self.id - }, - ) - .map(|result| { - result - .map(|x| x.unwrap()) - .map(|mut row| { - let (id, user_id, name, price) = from_row(row); - Product { - id, - user_id, - name, - price, - } - }) - .collect() - }) - .unwrap() + conn.prep_exec( + "select * from product where user_id=:user_id", + params! { + "user_id" => &self.id + }, + ) + .map(|result| { + result + .map(|x| x.unwrap()) + .map(|mut row| { + let (id, user_id, name, price) = from_row(row); + Product { + id, + user_id, + name, + price, + } + }) + .collect() + }) + .unwrap() } } diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index 6356c206..8a830ae5 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -2,7 +2,6 @@ use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; use futures::executor; use std::{sync::mpsc, thread}; - #[get("/hello")] async fn hello() -> &'static str { "Hello world!"