Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Builder for configuring and running the validation code generator.

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Create a new builder with default settings.

Source

pub fn file_descriptor_set_bytes(self, bytes: Vec<u8>) -> Self

Set the file descriptor set bytes directly.

Source

pub fn file_descriptor_set_path( self, path: impl AsRef<Path>, ) -> Result<Self, Error>

Read the file descriptor set from a file path.

§Errors

Returns an error if the file cannot be read.

Source

pub fn out_dir(self, path: impl Into<PathBuf>) -> Self

Override the output directory (defaults to OUT_DIR env var).

Source

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");
Source

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).

Source

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.

Source

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.

Source

pub fn compile(self) -> Result<(), Error>

Run the code generator.

§Errors

Returns an error if the descriptor set is missing, cannot be parsed, or the output file cannot be written.

Trait Implementations§

Source§

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.