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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Valitron is an ergonomics, functional and configurable validator.
//!
//! ## This is an example:
//!
//! ```rust
//! # use serde::{Deserialize, Serialize};
//! # use valitron::{
//! # available::{Message, Required, StartWith},
//! # custom, RuleExt, Validator
//! # };
//! #[derive(Serialize, Debug)]
//! struct Person {
//! introduce: &'static str,
//! age: u8,
//! weight: f32,
//! }
//!
//! # fn main() {
//! let validator = Validator::new()
//! .rule("introduce", Required.and(StartWith("I am")))
//! .rule("age", custom(age_range))
//! .message([
//! ("introduce.required", "introduce is required"),
//! (
//! "introduce.start_with",
//! "introduce should be starts with `I am`",
//! ),
//! ]);
//!
//! let person = Person {
//! introduce: "hi",
//! age: 18,
//! weight: 20.0,
//! };
//!
//! let res = validator.validate(person).unwrap_err();
//! assert!(res.len() == 2);
//! # }
//!
//! fn age_range(age: &mut u8) -> Result<(), Message> {
//! if *age >= 25 && *age <= 45 {
//! Ok(())
//! } else {
//! Err("age should be between 25 and 45".into())
//! }
//! }
//! ```
//!
//! The second scheme is [string].
//!
//! ## Prerequisite
//!
//! input data needs implementation `serde::Serialize`, and if you want to modify data,
//! it should be also implementation `serde::Deserialize`
//!
//! ## Available Rules
//!
//! - [`Compare`]
//! - [`Confirm`]
//! - [`Contains`]
//! - [`Email`]
//! - [`EndWith`]
//! - [`Length`]
//! - [`Not`]
//! - [`Range`]
//! - [`Regex`]
//! - [`Required`]
//! - [`StartWith`]
//! - [`Trim`]
//! - customizable
//!
//! To get started using all of Valitron's optional rule, add this to your
//! `Cargo.toml`:
//!
//! ```toml
//! valitron = { version = "0.1", features = ["full"] }
//! ```
//!
//! ## Closure Rule
//!
//! This is support closure with a primitive type mutable reference arguments and returning `message type`.
//!
//! > ### Tip
//! > `message type` is [`Validator`]'s only one generics argument, default is `String`, but when `full` features
//! > enabled default is [`Message`], and it is customable. And it's not immutable, it can be changed by [`map`] method.
//!
//! ## Custom Rule
//!
//! anything types implemented [`Rule`] trait can be used as a rule
//!
//! [`map`]: crate::register::Validator::map
//! [`Rule`]: crate::Rule
//! [`Message`]: crate::available::Message
//! [`Required`]: crate::available::required
//! [`Email`]: crate::available::email
//! [`Compare`]: crate::available::compare
//! [`Contains`]: crate::available::contains
//! [`StartWith`]: crate::available::start_with
//! [`EndWith`]: crate::available::end_with
//! [`Confirm`]: crate::available::confirm
//! [`Trim`]: crate::available::trim
//! [`Length`]: crate::available::length
//! [`Not`]: crate::available::not
//! [`Range`]: crate::available::range
//! [`Regex`]: crate::available::regex
//! [string]: crate::register::string
//#![warn(clippy::unwrap_used)]
//#![doc(html_playground_url = "https://play.rust-lang.org/")]
pub
pub use ;
pub use ;
pub use ;
pub use available;