diff --git a/src/context.rs b/src/context.rs new file mode 100644 index 0000000..27a17e1 --- /dev/null +++ b/src/context.rs @@ -0,0 +1,43 @@ +use serde::Serialize; + +#[derive(Serialize)] +pub struct FormContext<'a> { + pub path_prefix: &'a str, + pub was_validated: bool, + pub id: u16, + pub name: &'a str, + pub email: &'a str, + pub telefon: &'a str, + 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, + } + } +}