This is a Rust implementation of protoc-gen-validate.
It must be used with prost generated code.
All validation rules are documented in the proto file or in the protoc-gen-validate documentation.
It provides two implementations:
- A derive based implementation in the prost-validate crate.
- A reflection based implementation in the prost-reflect-validate crate.
The test suite adapted from the protoc-gen-validate harness tests is shared between the two implementations.
Here are the benchmarks for the tests suite of the two implementations:
prost-reflect-validate
:
harness reflect time: [14.849 ms 15.128 ms 15.459 ms]
prost-validate
:
harness derive time: [2.5635 ms 2.5780 ms 2.5967 ms]
Constraint Rule | Derive | Reflect |
---|---|---|
disabled | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
const | ✅ | ✅ |
lt/lte/gt/gte | ✅ | ✅ |
in/not_in | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
const | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
const | ✅ | ✅ |
len/min_len/max_len | ✅ | ✅ |
min_bytes/max_bytes | ✅ | ✅ |
pattern | ✅ | ✅ |
prefix/suffix/contains | ✅ | ✅ |
contains/not_contains | ✅ | ✅ |
in/not_in | ✅ | ✅ |
✅ | ✅ | |
hostname | ✅ | ✅ |
address | ✅ | ✅ |
ip | ✅ | ✅ |
ipv4 | ✅ | ✅ |
ipv6 | ✅ | ✅ |
uri | ✅ | ✅ |
uri_ref | ✅ | ✅ |
uuid | ✅ | ✅ |
well_known_regex | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
const | ✅ | ✅ |
len/min_len/max_len | ✅ | ✅ |
pattern | ✅ | ✅ |
prefix/suffix/contains | ✅ | ✅ |
in/not_in | ✅ | ✅ |
ip | ✅ | ✅ |
ipv4 | ✅ | ✅ |
ipv6 | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
const | ✅ | ✅ |
defined_only | ✅ | ✅ |
in/not_in | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
skip | ✅ | ✅ |
required | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
min_items/max_items | ✅ | ✅ |
unique | ✅ | ✅ |
items | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
min_pairs/max_pairs | ✅ | ✅ |
no_sparse | ❓ | ❓ |
keys | ✅ | ✅ |
values | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
required | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
wrapper validation | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
required | ✅ | ✅ |
in/not_in | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
required | ✅ | ✅ |
const | ✅ | ✅ |
lt/lte/gt/gte | ✅ | ✅ |
in/not_in | ✅ | ✅ |
Constraint Rule | Derive | Reflect |
---|---|---|
required | ✅ | ✅ |
const | ✅ | ✅ |
lt/lte/gt/gte | ✅ | ✅ |
lt_now/gt_now | ✅ | ✅ |
within | ✅ | ✅ |