web/pages/validation/
feedback.rs1use askama::Template;
2use std::fmt;
3
4pub enum ValidationStatus {
5 Error(String),
6 Success(String),
7 Notice(String),
8}
9
10impl fmt::Display for ValidationStatus {
11 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12 match self {
13 ValidationStatus::Error(msg) => write!(f, "{msg}"),
14 ValidationStatus::Success(msg) => write!(f, "{msg}"),
15 ValidationStatus::Notice(msg) => write!(f, "{msg}"),
16 }
17 }
18}
19
20#[derive(Template)]
21#[template(path = "components/validation/feedback.html")]
22pub struct ValidationFeedback {
23 status: ValidationStatus,
24}
25
26impl ValidationFeedback {
27 pub fn error(message: impl Into<String>) -> Self {
28 Self {
29 status: ValidationStatus::Error(message.into()),
30 }
31 }
32
33 pub fn success(message: impl Into<String>) -> Self {
34 Self {
35 status: ValidationStatus::Success(message.into()),
36 }
37 }
38
39 pub fn notice(message: impl Into<String>) -> Self {
40 Self {
41 status: ValidationStatus::Notice(message.into()),
42 }
43 }
44
45 #[must_use]
47 pub const fn is_error(&self) -> bool {
48 matches!(self.status, ValidationStatus::Error(_))
49 }
50
51 #[must_use]
52 pub const fn is_notice(&self) -> bool {
53 matches!(self.status, ValidationStatus::Notice(_))
54 }
55}