Skip to content

michaelni678/vate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vate

Rust data validation framework

Overview

  • 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.

Installation

Currently not on crates.io. Specify the dependency using this git repository instead.

vate = { git = "https://github.com/michaelni678/vate" }

Usage

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages