validator_struct

Crates.iovalidator_struct
lib.rsvalidator_struct
version0.3.1
sourcesrc
created_at2024-02-23 21:14:35.741244
updated_at2024-04-26 18:21:06.908189
descriptionA simple ergonomic addition to the validator crate
homepage
repositoryhttps://github.com/SorenHolstHansen/validator_struct
max_upload_size
id1151004
size12,047
Søren Hansen (SorenHolstHansen)

documentation

README

validator_struct

A simple ergonomic addition to the validator crate.

Usage

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();
}
Commit count: 10

cargo fmt