- Struct and Enum Validation: Automatically derive validation logic for structs and enums using the
Validate
procedural macro. - Built-in Validators: Utilize the built-in validators for common use cases.
- Custom Validators: Define your own validators tailored to your specific needs.
- Custom Errors: Declare your own validation error messages.
Currently not on crates.io. Specify the dependency using this git repository instead.
vate = { git = "https://github.com/michaelni678/vate" }
/// A request to create a user.
#[derive(Validate)]
struct CreateUser {
/// The user's username, which must be alphanumeric and between 4 and 20 characters.
#[vate(Alphanumeric, Length::Chars(Within { min: 4, max: 32 }))]
username: String,
/// The user's password, which must be ASCII and greater than 8 characters long.
#[vate(Ascii, Length::Chars(GE(8)))]
password: String,
/// The password confirmation, which must be equal to the password.
#[vate(EQ(password))]
confirm_password: String,
}
let mut report = BasicReport::default();
let _ = create_user
.validate(context, interpreter, interpreter_data, &mut report)
.unwrap();