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
/// A module that contains all the rules
/// A convenience module appropriate for glob imports `use type_rules::prelude::*;`
pub use *;
pub use Rule;
pub use Valid;
/// Check the validity of a type
///
/// By implementing `Validator` for a type, you define the
/// rules to check is validity
///
/// Can be derived with the `derive` feature
///
/// # Example
///
/// Basic usage:
///
/// ```should_panic
/// use type_rules::prelude::*;
///
/// #[derive(Validator)]
/// struct NotEmptyString(#[rule(MinLength(1))] String);
///
/// let valid = NotEmptyString(String::from("Not empty"));
/// let not_valid = NotEmptyString(String::from(""));
///
/// valid.check_validity().unwrap(); // OK
/// not_valid.check_validity().unwrap(); // Value is too short
/// ```