valust

Crates.iovalust
lib.rsvalust
version
sourcesrc
created_at2025-01-10 09:45:07.046916+00
updated_at2025-01-24 13:24:42.717111+00
descriptionA data validation library for Rust
homepage
repositoryhttps://github.com/Embers-of-the-Fire/valust-rs
max_upload_size
id1511089
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Wang BingHao (Embers-of-the-Fire)

documentation

README

Valust - Validator for Rust

Crate VersionGitHub top language Crates.io Downloads (recent)


Valust aims to provide a user-friendly, auto-generated data validation tool.

By leveraging Rust's powerful procedural macro system, valust can automatically generate everything you need for data validation with just a few simple attributes added to your data structures.

Example

use valust::{Validate, Raw};
use valust_derive::Valust;

#[derive(Debug, Valust, PartialEq)]
#[forward_derive(Debug)]
#[rename(UncheckedUsername)]
pub struct Username(
    #[trans(expr(String => _0.trim().to_owned()))]
    #[valid(expr(!_0.is_empty(), "username must not be empty"))]
    pub String,
);

#[derive(Debug, Valust, PartialEq)]
#[forward_derive(Debug)]
#[post(user_id + (username.0.len() as u32) == *magic_number)]
pub struct UserProfile {
    pub user_id: u32,
    #[forward]
    pub username: Username,
    pub magic_number: u32,
}

let raw_profile = Raw::<UserProfile> {
    user_id: 10,
    username: UncheckedUsername("  Foo  ".into()),
    magic_number: 13,
};

let profile = UserProfile::validate(raw_profile).expect("Check failed");

assert_eq!(profile, UserProfile {
    user_id: 10,
    username: Username("Foo".into()),
    magic_number: 13
});

Project Structure

Core

  • valust: Main crate, exposing fundamental traits (trait Validate) and error types.
  • valust-derive: Derive macro for creating a validate-able struct.

External Tools & Utilities

Minimum Supported Rust Version (MSRV)

The MSRV of this project is 1.78.0 (With lockfile version 4), but is possibly able to compile unlocked with Rust 1.74.1 (With lockfile version 3).

And for development, the project requires Rust 1.83.0 to work on the source code.

Commit count: 47

cargo fmt