prost-validate
A protobuf library extending prost with validation support.
This is a rust implementation of protoc-gen-validate.
It uses the prost crate to generate the derive based validation code.
For a reflection based implementation see the prost-reflect-validate crate.
Usage
It must be used with prost generated code.
All validation rules are documented in the proto file or in the protoc-gen-validate documentation.
Proto definition
proto/message.proto:
syntax = "proto3";
package validate.example;
import "validate/validate.proto";
message ExampleMessage {
string content = 1 [(validate.rules).string = {const: "Hello, world!"}];
}
Build script
build.rs:
Validation
Include the generated code
include!;
Using the generated code
Output:
Validation failed: "validate.example.ExampleMessage.content": must be equal to "Hello, world!"
Validation passed