From 635e7e4266eae98118397bfd5532c65ab6e7f9eb Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sat, 29 Oct 2022 17:55:00 +0200 Subject: [PATCH] No need for context constructor --- src/context.rs | 32 +------------------------------- src/routes.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/context.rs b/src/context.rs index 27a17e1..9c7ed0d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,7 +1,7 @@ use serde::Serialize; #[derive(Serialize)] -pub struct FormContext<'a> { +pub struct ContactFormContext<'a> { pub path_prefix: &'a str, pub was_validated: bool, pub id: u16, @@ -11,33 +11,3 @@ pub struct FormContext<'a> { pub message: &'a str, pub captcha: &'a str, } - -impl<'a> FormContext<'a> { - pub fn new( - path_prefix: &'a str, - was_validated: Option, - id: u16, - name: Option<&'a str>, - email: Option<&'a str>, - telefon: Option<&'a str>, - message: Option<&'a str>, - captcha: &'a str, - ) -> Self { - let was_validated = was_validated.unwrap_or(false); - let name = name.unwrap_or(""); - let email = email.unwrap_or(""); - let telefon = telefon.unwrap_or(""); - let message = message.unwrap_or(""); - - Self { - path_prefix, - was_validated, - id, - name, - email, - telefon, - message, - captcha, - } - } -} diff --git a/src/routes.rs b/src/routes.rs index 7d95c4e..505d8c2 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -29,16 +29,16 @@ pub fn index( let id = captcha_solutions.store_solution(&captcha.chars_as_string()); - let form_context = context::FormContext::new( - &config.path_prefix, - was_validated, + let form_context = context::ContactFormContext { + path_prefix: &config.path_prefix, + was_validated: was_validated.unwrap_or(false), id, - name, - email, - telefon, - message, - &captcha_base64, - ); + name: name.unwrap_or(""), + email: email.unwrap_or(""), + telefon: telefon.unwrap_or(""), + message: message.unwrap_or(""), + captcha: &captcha_base64, + }; Ok(Template::render("form", form_context)) }