Fixes some Clippy remarks.

This commit is contained in:
Dennis Brentjes 2025-05-19 21:01:38 +02:00
parent c994321576
commit 3f7ed03973
5 changed files with 30 additions and 18 deletions

View File

@ -13,7 +13,7 @@ use crate::util::GetConnection;
impl GamenightPost { impl GamenightPost {
pub fn into_with_user(&self, user: User) -> Result<schema::gamenight::Gamenight, ParseError> { pub fn into_with_user(&self, user: User) -> Result<schema::gamenight::Gamenight, ParseError> {
return Ok(schema::gamenight::Gamenight { Ok(schema::gamenight::Gamenight {
datetime: DateTime::parse_from_rfc3339(&self.datetime)?.with_timezone(&chrono::Utc), datetime: DateTime::parse_from_rfc3339(&self.datetime)?.with_timezone(&chrono::Utc),
id: Uuid::new_v4(), id: Uuid::new_v4(),
name: self.name.clone(), name: self.name.clone(),
@ -22,9 +22,9 @@ impl GamenightPost {
} }
} }
impl Into<Uuid> for GamenightGet { impl From<GamenightGet> for Uuid {
fn into(self) -> Uuid { fn from(value: GamenightGet) -> Self {
Uuid::parse_str(self.id.as_str()).unwrap() Uuid::parse_str(value.id.as_str()).unwrap()
} }
} }

View File

@ -11,21 +11,21 @@ use crate::util::GetConnection;
use crate::schema::{self}; use crate::schema::{self};
use serde_json; use serde_json;
impl Into<schema::user::LoginUser> for Login { impl From<Login> for schema::user::LoginUser {
fn into(self) -> schema::user::LoginUser { fn from(val: Login) -> Self {
schema::user::LoginUser { schema::user::LoginUser {
username: self.username, username: val.username,
password: self.password password: val.password
} }
} }
} }
impl Into<schema::user::Register> for Register { impl From<Register> for schema::user::Register {
fn into(self) -> schema::user::Register { fn from(val: Register) -> Self {
schema::user::Register { schema::user::Register {
email: self.email, email: val.email,
username: self.username, username: val.username,
password: self.password password: val.password
} }
} }
} }
@ -62,7 +62,7 @@ pub async fn register(pool: web::Data<DbPool>, register_data: web::Json<Register
Ok(()) Ok(())
}).await??; }).await??;
return Ok(HttpResponse::Ok()) Ok(HttpResponse::Ok())
} }

View File

@ -77,7 +77,7 @@ pub fn login(conn: &mut PgConnection, user: LoginUser) -> Result<Option<User>, D
let parsed_hash = PasswordHash::new(&pwd)?; let parsed_hash = PasswordHash::new(&pwd)?;
if Argon2::default() if Argon2::default()
.verify_password(&user.password.as_bytes(), &parsed_hash) .verify_password(user.password.as_bytes(), &parsed_hash)
.is_ok() .is_ok()
{ {
Ok(Some(users::table.find(id).first(conn)?)) 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) diesel::insert_into(users::table)
.values(User { .values(User {
id: id.clone(), id,
username: register.username, username: register.username,
email: register.email, email: register.email,
role: Role::User, role: Role::User,

View File

@ -15,11 +15,17 @@ impl Main {
main_menu.menu.push(Box::new(Exit::new())); main_menu.menu.push(Box::new(Exit::new()));
Self { Self {
login: Box::new(Login::new()), login: Box::new(Login::new()),
main_menu: main_menu main_menu
} }
} }
} }
impl Default for Main {
fn default() -> Self {
Self::new()
}
}
#[async_trait] #[async_trait]
impl<'a> Flow<'a> for Main { impl<'a> Flow<'a> for Main {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {

View File

@ -26,6 +26,12 @@ impl GamenightState {
} }
} }
impl Default for GamenightState {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct FlowError { pub struct FlowError {
pub error: String pub error: String
@ -85,7 +91,7 @@ async fn handle_choice<'a>(choice: &Box<dyn Flow<'a> + Send>, flow: &dyn Flow<'a
async fn handle_choice_option<'a>(choice: &Option<Box<dyn Flow<'a> + Send>>, flow: &dyn Flow<'a>, state: &'a mut GamenightState) -> FlowResult<'a> { async fn handle_choice_option<'a>(choice: &Option<Box<dyn Flow<'a> + Send>>, flow: &dyn Flow<'a>, state: &'a mut GamenightState) -> FlowResult<'a> {
if let Some(choice) = choice { if let Some(choice) = choice {
handle_choice(&choice, flow, state).await handle_choice(choice, flow, state).await
} }
else { else {
Ok((FlowOutcome::Abort, state)) Ok((FlowOutcome::Abort, state))