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
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(not(feature = "std"), no_std)]
pub mod context;
pub mod prelude {
pub use super::{
context::Context as ValidationContext, Result as ValidationResult, Validate, Validation,
};
}
use context::Context;
use core::{any::Any, fmt::Debug};
pub type Result<V> = core::result::Result<(), Context<V>>;
pub trait Validation: Any + Debug {}
impl<V> Validation for V where V: Any + Debug {}
pub trait Validate
{
type Validation: Validation;
fn validate(&self) -> Result<Self::Validation>;
}
#[cfg(test)]
mod tests {
use super::*;
struct Dummy;
impl Validate for Dummy {
type Validation = ();
fn validate(&self) -> Result<Self::Validation> {
Context::default().into_result()
}
}
#[test]
fn validate_dummy() {
assert!(Dummy.validate().is_ok());
}
}