Expand description
Runtime validation for Protocol Buffer messages using
buf.validate rules.
This crate dynamically inspects prost-reflect message descriptors at runtime,
compiles buf.validate constraint annotations (including CEL expressions),
and evaluates them against concrete message instances.
§Quick start
For one-off validation, use the validate convenience function:
use prost_protovalidate::validate;
match validate(&msg) {
Ok(()) => { /* message is valid */ }
Err(e) => eprintln!("validation failed: {e}"),
}For repeated validations, construct a Validator once to cache compiled
rules across calls:
use prost_protovalidate::Validator;
let validator = Validator::new();
validator.validate(&msg).expect("message should be valid");§Error types
| Type | When |
|---|---|
ValidationError | One or more constraint violations detected |
CompilationError | A CEL expression or constraint definition failed to parse |
RuntimeError | An unexpected failure during evaluation |
All three are unified under Error.
§Re-exported types
The types module re-exports prost-protovalidate-types
so consumers do not need to depend on it directly.
Re-exports§
pub use prost_protovalidate_types as types;
Structs§
- Compilation
Error - Returned when a validation rule cannot be compiled from its descriptor.
- Runtime
Error - Returned when runtime evaluation of dynamic rules fails.
- Validation
Error - Returned when one or more validation rules are violated.
- Validator
- Thread-safe validator for Protocol Buffer messages.
- Violation
- A single instance where a validation rule was not met.
Enums§
- Error
- Top-level error type returned by validation.
- Validation
Option - Options for configuring a single
Validator::validate_withcall. - Validator
Option - Options for configuring the
Validatorat construction time.
Traits§
- Filter
- Controls which fields/messages are validated.
Functions§
- normalize_
edition_ descriptor_ set - Normalize protobuf Edition 2023 descriptors to proto3 format for
compatibility with
prost-reflect0.16 which does not support editions. Normalize aFileDescriptorSetso that any Edition 2023 files are rewritten asproto3. Returns the original bytes unchanged if no edition files are detected. - validate
- Validate a message using a global
Validatorinstance.