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

#1986 in Parser implementations

Download history 97/week @ 2024-07-22 206/week @ 2024-07-29 49/week @ 2024-08-05 145/week @ 2024-08-12 79/week @ 2024-08-19 31/week @ 2024-08-26 67/week @ 2024-09-02 53/week @ 2024-09-09 81/week @ 2024-09-16 91/week @ 2024-09-23 186/week @ 2024-09-30 62/week @ 2024-10-07 69/week @ 2024-10-14 23/week @ 2024-10-21 102/week @ 2024-10-28 85/week @ 2024-11-04

280 downloads per month

MIT license

28KB
594 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.3–1.8MB
~42K SLoC