#validation #macro-derive #addition

macro validator_struct

A simple ergonomic addition to the validator crate

6 releases

new 0.3.1 Apr 26, 2024
0.3.0 Apr 26, 2024
0.2.2 Apr 26, 2024
0.2.1 Feb 25, 2024
0.1.0 Feb 23, 2024

#322 in Procedural macros

Download history 56/week @ 2024-02-17 420/week @ 2024-02-24 22/week @ 2024-03-02 6/week @ 2024-03-09 2/week @ 2024-03-16 42/week @ 2024-03-30 3/week @ 2024-04-06 90/week @ 2024-04-13

135 downloads per month

MIT license

10KB
195 lines

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();
}

Dependencies

~5.5–8MB
~170K SLoC