Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tu6ge/valitron
Valitron is a rust validation, support ergonomics, functional and configurable
https://github.com/tu6ge/valitron
actix-web axum functional rust-validator validation validator
Last synced: about 1 month ago
JSON representation
Valitron is a rust validation, support ergonomics, functional and configurable
- Host: GitHub
- URL: https://github.com/tu6ge/valitron
- Owner: tu6ge
- License: apache-2.0
- Created: 2023-08-18T09:20:44.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-05-23T02:09:01.000Z (about 1 month ago)
- Last Synced: 2024-05-23T05:41:45.360Z (about 1 month ago)
- Topics: actix-web, axum, functional, rust-validator, validation, validator
- Language: Rust
- Homepage: https://docs.rs/valitron
- Size: 371 KB
- Stars: 50
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Lists
- awesome-rust - tu6ge/valitron
README
# Valitron is an ergonomic, functional and configurable validator
In the future, modularization will be supported
Inspired by axum
## Features
- Ergonomics validation
- Build-in rule, e.g. Required, StartWith ...
- Closure validate
- Related validate, e.g. password confirm
- Custom rule with other parameter
- Check / modify input data
- Custom error message type
- Support different error types convert, it can use both build-in rules and custom error type simultaneously
- Collect validate error messages
- Support all types data on `#[derive(Serialize, Deserialize)]` ( visit [`serde`](https://serde.rs/) for more info)## Examples
```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())
}
```## Rules Usage
|Usage| Description|
|---|--- |
| `Required` | one rule |
| `Required.and(StartsWith("foo"))` | multi rules |
| `Required.and(StartsWith('a')).bail()`| multi rules and bail|
| `custom(my_handler)` | custom handler rule |
| `Required.custom(my_handler)` | rule and handler rule |
| `Not(StartsWith("foo"))` | negative rule |
| `Required.and(Not(StartsWith("foo")))` | negative rule |## Bench
| [second scheme](https://github.com/tu6ge/valitron/blob/string/examples/string.rs)| validator(lib) |
| --- | --- |
| 192.55 ns | 680.43 ns |#### License
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.