1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#[cfg(feature = "card")]
pub mod cards;
pub mod contains;
pub mod email;
pub mod ip;
pub mod length;
pub mod must_match;
#[cfg(feature = "phone")]
pub mod phone;
pub mod range;
pub mod urls;
#[derive(Debug, Clone, PartialEq)]
pub enum Validator {
Email,
Url,
Custom(String),
MustMatch(String),
Contains(String),
Regex(String),
Range {
min: f64,
max: f64,
},
Length {
min: Option<u64>,
max: Option<u64>,
equal: Option<u64>,
},
#[cfg(feature = "card")]
CreditCard,
#[cfg(feature = "phone")]
Phone,
Nested,
}
impl Validator {
pub fn code(&self) -> &'static str {
match *self {
Validator::MustMatch(_) => "must_match",
Validator::Email => "email",
Validator::Url => "url",
Validator::Custom(_) => "custom",
Validator::Contains(_) => "contains",
Validator::Regex(_) => "regex",
Validator::Range { .. } => "range",
Validator::Length { .. } => "length",
#[cfg(feature = "card")]
Validator::CreditCard => "credit_card",
#[cfg(feature = "phone")]
Validator::Phone => "phone",
Validator::Nested => "nested",
}
}
}