diff --git a/Cargo.toml b/Cargo.toml index 6c38cccc..efb308af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ futures-util = "0.3.26" async-stream = "0.3.4" config = { version = "0.13.3", default-features = false, features = ["yaml"] } once_cell = "1.13.0" -chrono = { version = "0.4.23", features = ["serde"] } +chrono = { version = "0.4.23", features = ["serde", "clock"] } derive_more = { version = "0.99" } uuid = { version = "1", features = ["v4", "serde"] } argon2 = { version = "0.5", features = ["std"] } diff --git a/crates/revdb/src/db.rs b/crates/revdb/src/db.rs index 8adafcfd..084951b3 100644 --- a/crates/revdb/src/db.rs +++ b/crates/revdb/src/db.rs @@ -50,7 +50,7 @@ impl RevDB { items.for_each(|(key, value)| { batch.insert(key.as_ref(), value); }); - let _ = self.db.apply_batch(batch)?; + self.db.apply_batch(batch)?; Ok(()) } } diff --git a/crates/revdb/src/document.rs b/crates/revdb/src/document.rs index 0b35a9ec..0d002bf1 100644 --- a/crates/revdb/src/document.rs +++ b/crates/revdb/src/document.rs @@ -15,7 +15,7 @@ impl<'a> Document<'a> { value: DocumentRevData, ) -> Result<(), RevDBError> { let key = make_document_key(uid, document_id, value.rev_id); - let _ = self.db.insert(key, &value.to_vec()?)?; + self.db.insert(key, &value.to_vec()?)?; Ok(()) } diff --git a/crates/revdb/tests/document/test.rs b/crates/revdb/tests/document/test.rs index 71552cce..8dbf51d1 100644 --- a/crates/revdb/tests/document/test.rs +++ b/crates/revdb/tests/document/test.rs @@ -19,6 +19,7 @@ fn insert_text() { assert_eq!(value.content, restored_data.content); } +//noinspection RsExternalLinter #[test] fn insert_multi_text() { let db = make_test_db(); @@ -51,6 +52,7 @@ fn insert_multi_text() { assert_eq!(expected_str, restored_str); } +//noinspection RsExternalLinter fn insert_100_string_to_document(uid: i64, document_id: i64, document: &Document) { let mut base_rev_id = 0; for i in 0..=100 { diff --git a/crates/token/Cargo.toml b/crates/token/Cargo.toml index acbc5c67..05452623 100644 --- a/crates/token/Cargo.toml +++ b/crates/token/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] serde = { version = "1.0", features = ["derive"] } -chrono = { version = "0.4.19", features = ["serde"] } +chrono = { version = "0.4.22", features = ["serde", "clock"] } jwt = "0.16.0" thiserror = "1.0.30" hmac = "0.12.1" diff --git a/src/api/user.rs b/src/api/user.rs index 1bcddfe7..ebf88191 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -25,7 +25,7 @@ async fn login_handler( ) -> Result { let req = req.into_inner(); let email = UserEmail::parse(req.email) - .map_err(|e| InputParamsError::InvalidEmail(e))? + .map_err(InputParamsError::InvalidEmail)? .0; let password = UserPassword::parse(req.password) .map_err(|_| InputParamsError::InvalidPassword)? @@ -52,10 +52,10 @@ async fn logout_handler(req: HttpRequest, state: Data) -> Result, state: Data) -> Result { let req = req.into_inner(); let name = UserName::parse(req.name) - .map_err(|e| InputParamsError::InvalidName(e))? + .map_err(InputParamsError::InvalidName)? .0; let email = UserEmail::parse(req.email) - .map_err(|e| InputParamsError::InvalidEmail(e))? + .map_err(InputParamsError::InvalidEmail)? .0; let password = UserPassword::parse(req.password) .map_err(|_| InputParamsError::InvalidPassword)? diff --git a/src/application.rs b/src/application.rs index f15906f6..545cb058 100644 --- a/src/application.rs +++ b/src/application.rs @@ -54,7 +54,7 @@ pub async fn run( let key = pair .as_ref() .map(|(_, server_key)| Key::from(server_key.expose_secret().as_bytes())) - .unwrap_or(Key::generate()); + .unwrap_or_else(Key::generate); let mut server = HttpServer::new(move || { App::new() // Session middleware diff --git a/src/component/auth/user.rs b/src/component/auth/user.rs index f4936eb5..bac06560 100644 --- a/src/component/auth/user.rs +++ b/src/component/auth/user.rs @@ -35,7 +35,7 @@ pub async fn login( state.user.write().await.authorized(logged_user); Ok(( LoginResponse { - token: token.clone().into(), + token: token.0.clone(), uid: uid.to_string(), }, Secret::new(token), @@ -99,7 +99,7 @@ pub async fn register( state.user.write().await.authorized(logged_user); Ok(RegisterResponse { - token: token.into(), + token: token.0.clone(), }) } @@ -209,13 +209,8 @@ pub struct ChangePasswordRequest { pub new_password_confirm: String, } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct WrapI64(i64); -impl Default for WrapI64 { - fn default() -> Self { - Self(0) - } -} impl Copy for WrapI64 {} impl DefaultIsZeroes for WrapI64 {} impl DebugSecret for WrapI64 {} @@ -323,15 +318,3 @@ pub fn uid_from_request( None => Err(AuthError::Unauthorized), } } - -impl From for Token { - fn from(val: String) -> Self { - Self(val) - } -} - -impl Into for Token { - fn into(self) -> String { - self.0 - } -} diff --git a/src/component/ws/server.rs b/src/component/ws/server.rs index 46078298..10a384fc 100644 --- a/src/component/ws/server.rs +++ b/src/component/ws/server.rs @@ -1,13 +1,9 @@ use crate::component::ws::entities::{Connect, Disconnect, WSError, WebSocketMessage}; use actix::{Actor, Context, Handler}; +#[derive(Default)] pub struct WSServer {} -impl std::default::Default for WSServer { - fn default() -> Self { - Self {} - } -} impl WSServer { pub fn new() -> Self { WSServer::default() diff --git a/src/config/mod.rs b/src/config/mod.rs index 47cf15af..b447bfee 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,2 +1,3 @@ +#![allow(clippy::module_inception)] pub mod config; pub mod env; diff --git a/tests/api/password.rs b/tests/api/password.rs index 23d7259b..957c9e4e 100644 --- a/tests/api/password.rs +++ b/tests/api/password.rs @@ -13,8 +13,8 @@ async fn change_password_with_unmatched_password() { .change_password( token, &test_user.password, - &new_password, - &new_password_confirm, + new_password, + new_password_confirm, ) .await; assert_eq!(http_resp.status(), StatusCode::BAD_REQUEST); @@ -28,7 +28,7 @@ async fn login_fail_after_change_password() { let new_password = "HelloWorld@1a"; let http_resp = server - .change_password(token, &test_user.password, &new_password, &new_password) + .change_password(token, &test_user.password, new_password, new_password) .await; assert_eq!(http_resp.status(), StatusCode::OK); @@ -44,10 +44,10 @@ async fn login_success_with_new_password() { let new_password = "HelloWorld@1a"; let http_resp = server - .change_password(token, &test_user.password, &new_password, &new_password) + .change_password(token, &test_user.password, new_password, new_password) .await; assert_eq!(http_resp.status(), StatusCode::OK); - let http_resp = server.login(&test_user.email, &new_password).await; + let http_resp = server.login(&test_user.email, new_password).await; assert_eq!(http_resp.status(), StatusCode::OK); }