Prost support for protoc-gen-validate annotations
Prost Validate
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.
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 Comparison
Global
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | disabled | โ | โ |
Numerics
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | const | โ | โ | | lt/lte/gt/gte | โ | โ | | in/not_in | โ | โ |
Bools
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | const | โ | โ |
Strings
| Constraint Rule | Derive | Reflect | |------------------------|:------:|:-------:| | const | โ | โ | | len/min\len/maxlen | โ | โ | | min\bytes/max\bytes | โ | โ | | pattern | โ | โ | | prefix/suffix/contains | โ | โ | | contains/not_contains | โ | โ | | in/not_in | โ | โ | | email | โ | โ | | hostname | โ | โ | | address | โ | โ | | ip | โ | โ | | ipv4 | โ | โ | | ipv6 | โ | โ | | uri | โ | โ | | uri_ref | โ | โ | | uuid | โ | โ | | wellknownregex | โ | โ |
Bytes
| Constraint Rule | Derive | Reflect | |------------------------|:------:|:-------:| | const | โ | โ | | len/min\len/maxlen | โ | โ | | pattern | โ | โ | | prefix/suffix/contains | โ | โ | | in/not_in | โ | โ | | ip | โ | โ | | ipv4 | โ | โ | | ipv6 | โ | โ |
Enums
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | const | โ | โ | | defined_only | โ | โ | | in/not_in | โ | โ |
Messages
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | skip | โ | โ | | required | โ | โ |
Repeated
| Constraint Rule | Derive | Reflect | |----------------------|:------:|:-------:| | min\items/maxitems | โ | โ | | unique | โ | โ | | items | โ | โ |
Maps
| Constraint Rule | Derive | Reflect | |----------------------|:------:|:-------:| | min\pairs/maxpairs | โ | โ | | no_sparse | โ | โ | | keys | โ | โ | | values | โ | โ |
OneOf
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | required | โ | โ |
WKT Scalar Value Wrappers
| Constraint Rule | Derive | Reflect | |--------------------|:------:|:-------:| | wrapper validation | โ | โ |
WKT Any
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | required | โ | โ | | in/not_in | โ | โ |
WKT Duration
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | required | โ | โ | | const | โ | โ | | lt/lte/gt/gte | โ | โ | | in/not_in | โ | โ |
WKT Timestamp
| Constraint Rule | Derive | Reflect | |-----------------|:------:|:-------:| | required | โ | โ | | const | โ | โ | | lt/lte/gt/gte | โ | โ | | ltnow/gtnow | โ | โ | | within | โ | โ |