From e60e7810de26300552b635849f8af323d38cd4f6 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 7 Oct 2021 03:04:59 +0100 Subject: [PATCH] clippy --- database_interactions/basic/src/db.rs | 1 + database_interactions/redis/src/main.rs | 8 ++++---- database_interactions/simple-auth-server/src/utils.rs | 4 ++-- forms/form/src/main.rs | 4 ++-- forms/multipart-async-std/src/main.rs | 6 ++---- graphql/juniper-advanced/src/handlers.rs | 2 +- graphql/juniper/src/main.rs | 2 +- json/jsonrpc/src/main.rs | 6 ++++-- websockets/chat-broker/src/server.rs | 3 +-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/database_interactions/basic/src/db.rs b/database_interactions/basic/src/db.rs index d7c7692..d8d4ec1 100644 --- a/database_interactions/basic/src/db.rs +++ b/database_interactions/basic/src/db.rs @@ -15,6 +15,7 @@ pub enum WeatherAgg { MonthAgg { year: i32, month: i32, total: f64 }, } +#[allow(clippy::enum_variant_names)] pub enum Queries { GetTopTenHottestYears, GetTopTenColdestYears, diff --git a/database_interactions/redis/src/main.rs b/database_interactions/redis/src/main.rs index bedbe18..8bf4f8d 100644 --- a/database_interactions/redis/src/main.rs +++ b/database_interactions/redis/src/main.rs @@ -40,10 +40,10 @@ async fn cache_stuff( .collect(); // successful operations return "OK", so confirm that all returned as so - if !res.iter().all(|res| match res { - Ok(RespValue::SimpleString(x)) if x == "OK" => true, - _ => false, - }) { + if !res + .iter() + .all(|res| matches!(res,Ok(RespValue::SimpleString(x)) if x == "OK")) + { Ok(HttpResponse::InternalServerError().finish()) } else { Ok(HttpResponse::Ok().body("successfully cached values")) diff --git a/database_interactions/simple-auth-server/src/utils.rs b/database_interactions/simple-auth-server/src/utils.rs index c672718..848efc3 100644 --- a/database_interactions/simple-auth-server/src/utils.rs +++ b/database_interactions/simple-auth-server/src/utils.rs @@ -5,7 +5,7 @@ lazy_static::lazy_static! { pub static ref SECRET_KEY: String = std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8)); } -const SALT: &'static [u8] = b"supersecuresalt"; +const SALT: &[u8] = b"supersecuresalt"; // WARNING THIS IS ONLY FOR DEMO PLEASE DO MORE RESEARCH FOR PRODUCTION USE pub fn hash_password(password: &str) -> Result { @@ -13,7 +13,7 @@ pub fn hash_password(password: &str) -> Result { secret: SECRET_KEY.as_bytes(), ..Default::default() }; - argon2::hash_encoded(password.as_bytes(), &SALT, &config).map_err(|err| { + argon2::hash_encoded(password.as_bytes(), SALT, &config).map_err(|err| { dbg!(err); ServiceError::InternalServerError }) diff --git a/forms/form/src/main.rs b/forms/form/src/main.rs index 0e0a76c..0381799 100644 --- a/forms/form/src/main.rs +++ b/forms/form/src/main.rs @@ -89,11 +89,11 @@ mod tests { fn as_str(&self) -> &str { match self { ResponseBody::Body(ref b) => match b { - Body::Bytes(ref by) => std::str::from_utf8(&by).unwrap(), + Body::Bytes(ref by) => std::str::from_utf8(by).unwrap(), _ => panic!(), }, ResponseBody::Other(ref b) => match b { - Body::Bytes(ref by) => std::str::from_utf8(&by).unwrap(), + Body::Bytes(ref by) => std::str::from_utf8(by).unwrap(), _ => panic!(), }, } diff --git a/forms/multipart-async-std/src/main.rs b/forms/multipart-async-std/src/main.rs index aefea22..7e24d0c 100644 --- a/forms/multipart-async-std/src/main.rs +++ b/forms/multipart-async-std/src/main.rs @@ -7,11 +7,9 @@ async fn save_file(mut payload: Multipart) -> Result { // iterate over multipart stream while let Ok(Some(mut field)) = payload.try_next().await { let content_type = field - .content_disposition() - .ok_or_else(|| actix_web::error::ParseError::Incomplete)?; + .content_disposition().ok_or(actix_web::error::ParseError::Incomplete)?; let filename = content_type - .get_filename() - .ok_or_else(|| actix_web::error::ParseError::Incomplete)?; + .get_filename().ok_or(actix_web::error::ParseError::Incomplete)?; let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename)); let mut f = async_std::fs::File::create(filepath).await?; diff --git a/graphql/juniper-advanced/src/handlers.rs b/graphql/juniper-advanced/src/handlers.rs index 0177f8e..458c67b 100644 --- a/graphql/juniper-advanced/src/handlers.rs +++ b/graphql/juniper-advanced/src/handlers.rs @@ -15,7 +15,7 @@ pub async fn graphql( }; let res = web::block(move || { let res = data.execute_sync(&schema, &ctx); - Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?) + serde_json::to_string(&res) }) .await .map_err(Error::from)?; diff --git a/graphql/juniper/src/main.rs b/graphql/juniper/src/main.rs index 4a790e2..cf6d61c 100644 --- a/graphql/juniper/src/main.rs +++ b/graphql/juniper/src/main.rs @@ -26,7 +26,7 @@ async fn graphql( ) -> Result { let user = web::block(move || { let res = data.execute_sync(&st, &()); - Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?) + serde_json::to_string(&res) }) .await?; Ok(HttpResponse::Ok() diff --git a/json/jsonrpc/src/main.rs b/json/jsonrpc/src/main.rs index c3c2e3d..f377465 100644 --- a/json/jsonrpc/src/main.rs +++ b/json/jsonrpc/src/main.rs @@ -33,8 +33,10 @@ async fn rpc_handler( .body(r.dump())); } }; - let mut result = convention::Response::default(); - result.id = reqjson.id.clone(); + let mut result = convention::Response { + id: reqjson.id.clone(), + ..convention::Response::default() + }; match rpc_select(&app_state, reqjson.method.as_str(), reqjson.params).await { Ok(ok) => result.result = ok, diff --git a/websockets/chat-broker/src/server.rs b/websockets/chat-broker/src/server.rs index 03cd252..aa02e3b 100644 --- a/websockets/chat-broker/src/server.rs +++ b/websockets/chat-broker/src/server.rs @@ -2,7 +2,6 @@ use actix::prelude::*; use actix_broker::BrokerSubscribe; use std::collections::HashMap; -use std::mem; use crate::message::{ChatMessage, JoinRoom, LeaveRoom, ListRooms, SendMessage}; @@ -17,7 +16,7 @@ pub struct WsChatServer { impl WsChatServer { fn take_room(&mut self, room_name: &str) -> Option { let room = self.rooms.get_mut(room_name)?; - let room = mem::replace(room, HashMap::new()); + let room = std::mem::take(room); Some(room) }