In the future, modularization will be supported
Inspired by axum
#[derive(Serialize, Deserialize)]
( visit serde
for more info)``rust
fn main() {
let validator = Validator::new()
.rule("name", Required.and(StartWith("hello")))
.rule("age", custom(age_limit))
.message([
("name.required", "name is required"),
("name.start_with", "name should be starts with
hello`"),
]);
let person = Person {
name: "li",
age: 18,
};
let res = validator.validate(person);
// or using trait
let res = person.validate(validator);
}
fn age_limit(n: &mut u8) -> Result<(), Message> { if *n >= 25 && *n <= 45 { return Ok(()); } Err("age should be between 25 and 45".into()) } ```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
My English proficiency is limited. If you have a better representation in the document, welcome to PR.