#validation #user-input

macro validatron_derive

A data structure validation library designed for user input

3 unstable releases

0.2.1 Feb 18, 2021
0.2.0 Jan 29, 2021
0.1.0 Jan 7, 2021

#445 in Encoding

Download history 54/week @ 2021-10-05 11/week @ 2021-10-12 46/week @ 2021-10-19 33/week @ 2021-10-26 14/week @ 2021-11-02 43/week @ 2021-11-09 35/week @ 2021-11-16 21/week @ 2021-11-23 39/week @ 2021-11-30 26/week @ 2021-12-07 29/week @ 2021-12-14 3/week @ 2021-12-21 2/week @ 2021-12-28 23/week @ 2022-01-04 9/week @ 2022-01-11 26/week @ 2022-01-18

61 downloads per month
Used in validatron

MIT license

11KB
258 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

~280–700KB
~17K SLoC