Expand description
Compile-time code generator for Protocol Buffer validation.
Generates impl prost_protovalidate::Validate for messages that have
only standard buf.validate rules (no CEL expressions). Validators
run through monomorphized direct field access at runtime — no
prost-reflect transcoding, no CEL interpreter on the hot path.
Messages with any CEL rules are excluded and must use the runtime
prost_protovalidate::Validator instead.
§Usage
In your build.rs:
fn main() -> Result<(), Box<dyn std::error::Error>> {
// First, compile protos with prost-build (writes descriptor set)
let descriptor_path = std::path::PathBuf::from(std::env::var("OUT_DIR")?)
.join("file_descriptor_set.bin");
prost_build::Config::new()
.file_descriptor_set_path(&descriptor_path)
.compile_protos(&["proto/service.proto"], &["proto/"])?;
// Then generate validation impls
prost_protovalidate_build::Builder::new()
.file_descriptor_set_path(&descriptor_path)?
.compile()?;
Ok(())
}Then include the generated code alongside the prost-generated code:
ⓘ
include!(concat!(env!("OUT_DIR"), "/validate_impl.rs"));Structs§
- Builder
- Builder for configuring and running the validation code generator.
Enums§
- Error
- Errors that can occur during code generation.