update README.md and doc tests

This commit is contained in:
gengteng
2023-10-09 14:57:58 +08:00
parent c421807bfc
commit cc4cd9f70c
9 changed files with 662 additions and 248 deletions

View File

@@ -1,4 +1,9 @@
//! # Validator support
//!
//! ## Feature
//!
//! Enable the `validator` feature (enabled by default) to use `Valid<E>` and `ValidEx<E, A>`.
//!
#[cfg(test)]
pub mod test;
@@ -287,6 +292,7 @@ where
#[cfg(test)]
pub mod tests {
use super::*;
use std::fmt::Formatter;
use std::io;
use validator::ValidationError;
const TEST: &str = "test";
@@ -299,6 +305,7 @@ pub mod tests {
inner.push_str(TEST);
v.deref_mut().push_str(TEST);
assert_eq!(&inner, v.deref());
println!("{}", v);
assert_eq!(inner, v.into_inner());
}
@@ -316,12 +323,18 @@ pub mod tests {
Ok(())
}
#[derive(Validate)]
#[derive(Debug, Validate)]
struct Data {
#[validate(custom(function = "validate", arg = "i32"))]
v: i32,
}
impl Display for Data {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
struct DataVA {
a: i32,
}
@@ -337,6 +350,7 @@ pub mod tests {
let data = Data { v: 12 };
let args = DataVA { a: 123 };
let ve = ValidEx(data, args);
println!("{}", ve);
assert_eq!(ve.v, 12);
let a = ve.arguments();
assert_eq!(a, 123);