Crates.io | validator_struct |
lib.rs | validator_struct |
version | 0.3.1 |
source | src |
created_at | 2024-02-23 21:14:35.741244 |
updated_at | 2024-04-26 18:21:06.908189 |
description | A simple ergonomic addition to the validator crate |
homepage | |
repository | https://github.com/SorenHolstHansen/validator_struct |
max_upload_size | |
id | 1151004 |
size | 12,047 |
A simple ergonomic addition to the validator crate.
We provide a simple ValidatorStruct
derive macro to make working with the validator crate easier.
They can be used alongside the Validate
derive macro like this
#[derive(Validate, ValidatorStruct)]
struct SignupData {
#[validate(email)]
mail: String,
#[validate(phone)]
phone: String,
#[validate(url)]
site: String,
#[validate(length(min = 1), custom = "validate_unique_username")]
#[serde(rename = "firstName")]
first_name: String,
#[validate(range(min = 18, max = 20))]
age: u32,
}
fn validate_signup_data(data: SignupData) {
// validate_struct() returns a SignupDataError struct
// Where each field is replaced by a `Vec<String>`
data.validate_struct();
}