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 {
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),
id: Uuid::new_v4(),
name: self.name.clone(),
@ -22,9 +22,9 @@ impl GamenightPost {
}
}
impl Into<Uuid> for GamenightGet {
fn into(self) -> Uuid {
Uuid::parse_str(self.id.as_str()).unwrap()
impl From<GamenightGet> for Uuid {
fn from(value: GamenightGet) -> Self {
Uuid::parse_str(value.id.as_str()).unwrap()
}
}

View File

@ -11,21 +11,21 @@ use crate::util::GetConnection;
use crate::schema::{self};
use serde_json;
impl Into<schema::user::LoginUser> for Login {
fn into(self) -> schema::user::LoginUser {
impl From<Login> 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<schema::user::Register> for Register {
fn into(self) -> schema::user::Register {
impl From<Register> 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<DbPool>, register_data: web::Json<Register
Ok(())
}).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)?;
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,

View File

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

View File

@ -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<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> {
if let Some(choice) = choice {
handle_choice(&choice, flow, state).await
handle_choice(choice, flow, state).await
}
else {
Ok((FlowOutcome::Abort, state))