1
0
mirror of https://github.com/actix/examples synced 2024-11-23 14:31:07 +01:00
This commit is contained in:
Rob Ede 2021-10-07 03:04:59 +01:00
parent bfede4c1bb
commit e60e7810de
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
9 changed files with 18 additions and 18 deletions

View File

@ -15,6 +15,7 @@ pub enum WeatherAgg {
MonthAgg { year: i32, month: i32, total: f64 },
}
#[allow(clippy::enum_variant_names)]
pub enum Queries {
GetTopTenHottestYears,
GetTopTenColdestYears,

View File

@ -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"))

View File

@ -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<String, ServiceError> {
@ -13,7 +13,7 @@ pub fn hash_password(password: &str) -> Result<String, ServiceError> {
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
})

View File

@ -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!(),
},
}

View File

@ -7,11 +7,9 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
// 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?;

View File

@ -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)?;

View File

@ -26,7 +26,7 @@ async fn graphql(
) -> Result<HttpResponse, Error> {
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()

View File

@ -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,

View File

@ -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<Room> {
let room = self.rooms.get_mut(room_name)?;
let room = mem::replace(room, HashMap::new());
let room = std::mem::take(room);
Some(room)
}