#validation #user-input #structure #derive #validatron

macro validatron_derive

A data structure validation library designed for user input

6 releases (breaking)

0.5.0 Oct 18, 2022
0.4.0 Oct 17, 2022
0.3.0 Oct 13, 2022
0.2.1 Feb 18, 2021
0.1.0 Jan 7, 2021

#110 in #user-input

Download history 16/week @ 2023-11-26 7/week @ 2023-12-03 20/week @ 2023-12-10 17/week @ 2024-01-07 36/week @ 2024-01-14 57/week @ 2024-01-21 61/week @ 2024-01-28 34/week @ 2024-02-04 26/week @ 2024-02-11 27/week @ 2024-02-18 56/week @ 2024-02-25 33/week @ 2024-03-03 47/week @ 2024-03-10

164 downloads per month
Used in validatron

MIT license

14KB
268 lines

Validatron Build Status Docs Latest Version

Validatron is a data structure validation library for Rust that is designed for performing extensive integrity checks on user supplied data prior to use.

It is heavily inspired by the keats/validator crate but with different design choices:

  • do not fail fast, return as many errors as possible
  • return a serializable error type
  • provide easily extendable validators

Example

(Check the examples directory for additional examples.)

use validatron::Validate;

#[derive(Debug, Validate)]
struct MyStruct {
    #[validatron(min = 42)]
    a: i64,
    #[validatron(max_len = 5)]
    b: Vec<u32>,
}

fn main() {
    let good = MyStruct {
        a: 666,
        b: vec![],
    };

    assert!(good.validate().is_ok());

    let bad = MyStruct {
        a: 1,
        b: vec![42; 25],
    };

    let result = bad.validate();
    assert!(result.is_err());

    println!("{:#?}", result);
}

License

validatron is licensed under the MIT license; see the LICENSE file for more details.

Dependencies

~1.5MB
~33K SLoC