| Crates.io | validex |
| lib.rs | validex |
| version | 0.1.1 |
| created_at | 2025-12-13 17:16:00.212085+00 |
| updated_at | 2025-12-17 23:37:37.650545+00 |
| description | Input validating library. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1983208 |
| size | 25,348 |
A Rust validation library.
Unlike validator library, which use syntex or string.
validex use concrete rust values in #[check(...)] attribute.
Any types that implement Check trait can be used in #[check(...)].
This enables IDE-friendly features like: auto-import/fix, goto-def, syntax highlight, hover docs, etc...
Check derive macros for validating structs.All, Any and Not combinators.Check trait.Add validex to your Cargo.toml:
[dependencies]
validex = "0.1"
Here is an simple example:
use validex::*;
fn validate_url(_: &impl AsRef<str>) -> Result<(), String> {
Ok(())
}
fn validate_user_id(id: &u32) -> Result<(), &'static str> {
if *id == 13 {
return Err("13 is an unlucky number");
}
Ok(())
}
#[derive(Check)]
struct UserData {
#[check(
Any((
Range(20..=30),
All((Not(45), Range(40..=50))),
100,
)),
validate_user_id
)]
id: u32,
#[check(Maybe((
Not("example.com"),
Length(..=20),
validate_url,
)))]
site: Option<String>,
#[check(Range(13..=28), Not(Range(18..=24)))]
age: u32,
}
#[derive(Check)]
struct User {
#[check(UserData::check)]
data: UserData,
}
fn main() {
let user = User {
data: UserData {
id: 45,
site: Some("personal-blog.net".into()),
age: 25,
},
};
if let Err(err) = user.check() {
println!("{:}", err);
}
}