7 releases

0.3.2 Jun 21, 2020
0.3.1 Jun 21, 2020
0.2.0 Jun 15, 2020
0.1.2 Jun 11, 2020

#1596 in Encoding

MIT license

130KB
3K SLoC

Verify

Latest Version Documentation

Verify is yet another validation library for Rust. Its main concept consists of validators that can validate values of any kind of structure. The idea is based on Serde's model, and there is even an optional wrapper for Serde-compatible types.

Basic Usage

The library itself without features doesn't do much, it only provides trait definitions and common types.

In order to use it you need to write or find a validator, or enable one of the implementation features of the library. There is official support only for Schemars at the moment.

This very basic example shows how to create a self-validating type with Verify and Schemars:

(Schemars doesn't yet provide a way to add additional rules during derive, but will in the future.)

#[derive(Default, Verify, Serialize, JsonSchema)]
#[verify(schemars, serde)]
struct ExampleStruct {
    example_value: i32,
}

fn main() {
    let example = ExampleStruct::default();
    
    // This will always return Ok(())
    assert!(example.verify().is_ok());
}

There are quite a few things happening behind the scenes. For more details, visit the documentation.

For more examples visit the examples directory.

Cargo Features

By default only the smallvec feature is enabled.

serde

Serde integration, it enables validating any value that implements Serialize.

smallvec

Use smallvec for some types instead of Vec in the library.

schemars

Enable Schemars integration by implementing Validator, Verifier and Verify for its schema types.

Dependencies

~1.3–2.3MB
~51K SLoC