pub struct Builder { /* private fields */ }Expand description
Builder for configuring and running the validation code generator.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn file_descriptor_set_bytes(self, bytes: Vec<u8>) -> Self
pub fn file_descriptor_set_bytes(self, bytes: Vec<u8>) -> Self
Set the file descriptor set bytes directly.
Sourcepub fn out_dir(self, path: impl Into<PathBuf>) -> Self
pub fn out_dir(self, path: impl Into<PathBuf>) -> Self
Override the output directory (defaults to OUT_DIR env var).
Sourcepub fn extern_path(
self,
proto_path: impl Into<String>,
rust_path: impl Into<String>,
) -> Self
pub fn extern_path( self, proto_path: impl Into<String>, rust_path: impl Into<String>, ) -> Self
Map a proto package path to a Rust module path.
This is equivalent to prost-build’s extern_path and should match
your prost-build configuration.
§Example
prost_protovalidate_build::Builder::new()
.extern_path(".my.package", "::my_crate::my_package");Sourcepub fn backend(self, backend: Backend) -> Self
pub fn backend(self, backend: Backend) -> Self
Select the protobuf runtime the generated impls target (defaults to
Backend::Prost).
Use Backend::Buffa when the message types were generated by
buffa-build (or a wrapper such as connectrpc-build): presence
checks go through MessageField, enum accesses through
EnumValue::to_i32, and type paths keep verbatim proto names
(UUID stays UUID — prost would rename it to Uuid).
Sourcepub fn fail_on_runtime_only(self, fail: bool) -> Self
pub fn fail_on_runtime_only(self, fail: bool) -> Self
Turn “route to runtime validator” outcomes into hard build errors.
By default, messages the generator cannot cover (CEL rules,
unsupported shapes) are skipped with a cargo:warning, on the
assumption that the runtime Validator picks them up. Consumers that
ship no runtime validation path (e.g. build-time-only validation
against a slim prost-protovalidate) must set this to true so a
rule can never be silently skipped.
Sourcepub fn runtime_bridge(self, enable: bool) -> Self
pub fn runtime_bridge(self, enable: bool) -> Self
Route messages the generator cannot cover to the runtime Validator
instead of skipping (cargo:warning) or hard-failing them.
In this mode a message with CEL rules (or a shape the generator does not
support) receives an impl Validate that encodes the value to protobuf
wire bytes and validates it through an embedded descriptor set — reusing
the full runtime engine, including the CEL interpreter, rather than a
second code path. This gives buffa-generated types full rule coverage
(matching the runtime Validator) at the cost of pulling
prost-protovalidate’s reflect/cel features into the consumer for
the routed messages.
§Feature tiers
The default build-time path (standard rules, especially with
fail_on_runtime_only) stays
reflection- and CEL-free. runtime_bridge is the explicit opt-in that
crosses into the runtime engine: the routed messages require
prost-protovalidate built with reflect (and cel for CEL rules),
otherwise the generated code fails to compile.
§OUT_DIR requirement
The generated bridge embeds the descriptor set next to the generated code
and loads it via include_bytes!(concat!(env!("OUT_DIR"), …)), so the
generated file must be included from OUT_DIR (the default). Do not
combine runtime_bridge with an out_dir override
for code that is subsequently compiled — the embedded descriptor set
would not be found.
Only supported with Backend::Buffa, and mutually exclusive with
Builder::fail_on_runtime_only; Builder::compile returns
Error::ConflictingOptions otherwise.