mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
clippy
This commit is contained in:
parent
bfede4c1bb
commit
e60e7810de
@ -15,6 +15,7 @@ pub enum WeatherAgg {
|
|||||||
MonthAgg { year: i32, month: i32, total: f64 },
|
MonthAgg { year: i32, month: i32, total: f64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
pub enum Queries {
|
pub enum Queries {
|
||||||
GetTopTenHottestYears,
|
GetTopTenHottestYears,
|
||||||
GetTopTenColdestYears,
|
GetTopTenColdestYears,
|
||||||
|
@ -40,10 +40,10 @@ async fn cache_stuff(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// successful operations return "OK", so confirm that all returned as so
|
// successful operations return "OK", so confirm that all returned as so
|
||||||
if !res.iter().all(|res| match res {
|
if !res
|
||||||
Ok(RespValue::SimpleString(x)) if x == "OK" => true,
|
.iter()
|
||||||
_ => false,
|
.all(|res| matches!(res,Ok(RespValue::SimpleString(x)) if x == "OK"))
|
||||||
}) {
|
{
|
||||||
Ok(HttpResponse::InternalServerError().finish())
|
Ok(HttpResponse::InternalServerError().finish())
|
||||||
} else {
|
} else {
|
||||||
Ok(HttpResponse::Ok().body("successfully cached values"))
|
Ok(HttpResponse::Ok().body("successfully cached values"))
|
||||||
|
@ -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));
|
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
|
// WARNING THIS IS ONLY FOR DEMO PLEASE DO MORE RESEARCH FOR PRODUCTION USE
|
||||||
pub fn hash_password(password: &str) -> Result<String, ServiceError> {
|
pub fn hash_password(password: &str) -> Result<String, ServiceError> {
|
||||||
@ -13,7 +13,7 @@ pub fn hash_password(password: &str) -> Result<String, ServiceError> {
|
|||||||
secret: SECRET_KEY.as_bytes(),
|
secret: SECRET_KEY.as_bytes(),
|
||||||
..Default::default()
|
..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);
|
dbg!(err);
|
||||||
ServiceError::InternalServerError
|
ServiceError::InternalServerError
|
||||||
})
|
})
|
||||||
|
@ -89,11 +89,11 @@ mod tests {
|
|||||||
fn as_str(&self) -> &str {
|
fn as_str(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
ResponseBody::Body(ref b) => match b {
|
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!(),
|
_ => panic!(),
|
||||||
},
|
},
|
||||||
ResponseBody::Other(ref b) => match b {
|
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!(),
|
_ => panic!(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,9 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
|
|||||||
// iterate over multipart stream
|
// iterate over multipart stream
|
||||||
while let Ok(Some(mut field)) = payload.try_next().await {
|
while let Ok(Some(mut field)) = payload.try_next().await {
|
||||||
let content_type = field
|
let content_type = field
|
||||||
.content_disposition()
|
.content_disposition().ok_or(actix_web::error::ParseError::Incomplete)?;
|
||||||
.ok_or_else(|| actix_web::error::ParseError::Incomplete)?;
|
|
||||||
let filename = content_type
|
let filename = content_type
|
||||||
.get_filename()
|
.get_filename().ok_or(actix_web::error::ParseError::Incomplete)?;
|
||||||
.ok_or_else(|| actix_web::error::ParseError::Incomplete)?;
|
|
||||||
let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename));
|
let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename));
|
||||||
let mut f = async_std::fs::File::create(filepath).await?;
|
let mut f = async_std::fs::File::create(filepath).await?;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub async fn graphql(
|
|||||||
};
|
};
|
||||||
let res = web::block(move || {
|
let res = web::block(move || {
|
||||||
let res = data.execute_sync(&schema, &ctx);
|
let res = data.execute_sync(&schema, &ctx);
|
||||||
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
|
serde_json::to_string(&res)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
@ -26,7 +26,7 @@ async fn graphql(
|
|||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let user = web::block(move || {
|
let user = web::block(move || {
|
||||||
let res = data.execute_sync(&st, &());
|
let res = data.execute_sync(&st, &());
|
||||||
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
|
serde_json::to_string(&res)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
|
@ -33,8 +33,10 @@ async fn rpc_handler(
|
|||||||
.body(r.dump()));
|
.body(r.dump()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut result = convention::Response::default();
|
let mut result = convention::Response {
|
||||||
result.id = reqjson.id.clone();
|
id: reqjson.id.clone(),
|
||||||
|
..convention::Response::default()
|
||||||
|
};
|
||||||
|
|
||||||
match rpc_select(&app_state, reqjson.method.as_str(), reqjson.params).await {
|
match rpc_select(&app_state, reqjson.method.as_str(), reqjson.params).await {
|
||||||
Ok(ok) => result.result = ok,
|
Ok(ok) => result.result = ok,
|
||||||
|
@ -2,7 +2,6 @@ use actix::prelude::*;
|
|||||||
use actix_broker::BrokerSubscribe;
|
use actix_broker::BrokerSubscribe;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
use crate::message::{ChatMessage, JoinRoom, LeaveRoom, ListRooms, SendMessage};
|
use crate::message::{ChatMessage, JoinRoom, LeaveRoom, ListRooms, SendMessage};
|
||||||
|
|
||||||
@ -17,7 +16,7 @@ pub struct WsChatServer {
|
|||||||
impl WsChatServer {
|
impl WsChatServer {
|
||||||
fn take_room(&mut self, room_name: &str) -> Option<Room> {
|
fn take_room(&mut self, room_name: &str) -> Option<Room> {
|
||||||
let room = self.rooms.get_mut(room_name)?;
|
let room = self.rooms.get_mut(room_name)?;
|
||||||
let room = mem::replace(room, HashMap::new());
|
let room = std::mem::take(room);
|
||||||
Some(room)
|
Some(room)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user