Separate context
This commit is contained in:
parent
dcfd6fe075
commit
a1b5d43ac5
1 changed files with 43 additions and 0 deletions
43
src/context.rs
Normal file
43
src/context.rs
Normal file
|
@ -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<bool>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue