From 3f7ed039735e64459e094005326487bef71645e8 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Mon, 19 May 2025 21:01:38 +0200 Subject: [PATCH] Fixes some Clippy remarks. --- .../src/request/gamenight_handlers.rs | 8 ++++---- backend-actix/src/request/user_handlers.rs | 20 +++++++++---------- backend-actix/src/schema/user.rs | 4 ++-- gamenight-cli/src/flows/main.rs | 8 +++++++- gamenight-cli/src/flows/mod.rs | 8 +++++++- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/backend-actix/src/request/gamenight_handlers.rs b/backend-actix/src/request/gamenight_handlers.rs index a33f5ac..94f9062 100644 --- a/backend-actix/src/request/gamenight_handlers.rs +++ b/backend-actix/src/request/gamenight_handlers.rs @@ -13,7 +13,7 @@ use crate::util::GetConnection; impl GamenightPost { pub fn into_with_user(&self, user: User) -> Result { - return Ok(schema::gamenight::Gamenight { + Ok(schema::gamenight::Gamenight { datetime: DateTime::parse_from_rfc3339(&self.datetime)?.with_timezone(&chrono::Utc), id: Uuid::new_v4(), name: self.name.clone(), @@ -22,9 +22,9 @@ impl GamenightPost { } } -impl Into for GamenightGet { - fn into(self) -> Uuid { - Uuid::parse_str(self.id.as_str()).unwrap() +impl From for Uuid { + fn from(value: GamenightGet) -> Self { + Uuid::parse_str(value.id.as_str()).unwrap() } } diff --git a/backend-actix/src/request/user_handlers.rs b/backend-actix/src/request/user_handlers.rs index 174b3d7..ab0711d 100644 --- a/backend-actix/src/request/user_handlers.rs +++ b/backend-actix/src/request/user_handlers.rs @@ -11,21 +11,21 @@ use crate::util::GetConnection; use crate::schema::{self}; use serde_json; -impl Into for Login { - fn into(self) -> schema::user::LoginUser { +impl From for schema::user::LoginUser { + fn from(val: Login) -> Self { schema::user::LoginUser { - username: self.username, - password: self.password + username: val.username, + password: val.password } } } -impl Into for Register { - fn into(self) -> schema::user::Register { +impl From for schema::user::Register { + fn from(val: Register) -> Self { schema::user::Register { - email: self.email, - username: self.username, - password: self.password + email: val.email, + username: val.username, + password: val.password } } } @@ -62,7 +62,7 @@ pub async fn register(pool: web::Data, register_data: web::Json Result, D let parsed_hash = PasswordHash::new(&pwd)?; if Argon2::default() - .verify_password(&user.password.as_bytes(), &parsed_hash) + .verify_password(user.password.as_bytes(), &parsed_hash) .is_ok() { Ok(Some(users::table.find(id).first(conn)?)) @@ -135,7 +135,7 @@ pub fn register(conn: &mut PgConnection, register: Register) -> Result<(), Datab diesel::insert_into(users::table) .values(User { - id: id.clone(), + id, username: register.username, email: register.email, role: Role::User, diff --git a/gamenight-cli/src/flows/main.rs b/gamenight-cli/src/flows/main.rs index c131118..a480fa3 100644 --- a/gamenight-cli/src/flows/main.rs +++ b/gamenight-cli/src/flows/main.rs @@ -15,11 +15,17 @@ impl Main { main_menu.menu.push(Box::new(Exit::new())); Self { login: Box::new(Login::new()), - main_menu: main_menu + main_menu } } } +impl Default for Main { + fn default() -> Self { + Self::new() + } +} + #[async_trait] impl<'a> Flow<'a> for Main { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { diff --git a/gamenight-cli/src/flows/mod.rs b/gamenight-cli/src/flows/mod.rs index 99a765f..a6c203e 100644 --- a/gamenight-cli/src/flows/mod.rs +++ b/gamenight-cli/src/flows/mod.rs @@ -26,6 +26,12 @@ impl GamenightState { } } +impl Default for GamenightState { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug)] pub struct FlowError { pub error: String @@ -85,7 +91,7 @@ async fn handle_choice<'a>(choice: &Box + Send>, flow: &dyn Flow<'a async fn handle_choice_option<'a>(choice: &Option + Send>>, flow: &dyn Flow<'a>, state: &'a mut GamenightState) -> FlowResult<'a> { if let Some(choice) = choice { - handle_choice(&choice, flow, state).await + handle_choice(choice, flow, state).await } else { Ok((FlowOutcome::Abort, state))