Crates.io | verify |
lib.rs | verify |
version | 0.3.2 |
source | src |
created_at | 2020-06-11 01:25:46.704952 |
updated_at | 2020-06-21 22:49:18.801832 |
description | A validation library |
homepage | |
repository | https://github.com/tamasfe/verify |
max_upload_size | |
id | 252571 |
size | 139,600 |
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.
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.
By default only the smallvec
feature is enabled.
Serde integration, it enables validating any value that implements Serialize.
Use smallvec for some types instead of Vec
in the library.
Enable Schemars integration by implementing Validator
, Verifier
and Verify
for its schema types.