Skip to main content

Builder

Struct Builder 

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

Builder for compiling .proto files with reflection metadata enabled.

Driving the build script:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    buffa_reflect_build::Builder::new()
        .file_descriptor_set_bytes("crate::FILE_DESCRIPTOR_SET_BYTES")
        .files(&["proto/acme/api/v1/user.proto"])
        .includes(&["proto/"])
        .compile()?;
    Ok(())
}

The downstream library then ships:

pub const FILE_DESCRIPTOR_SET_BYTES: &[u8] =
    include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin"));

buffa::include_proto!("acme.api.v1");

Every generated message is decorated with #[derive(::buffa_reflect::ReflectMessage)] so that m.descriptor() resolves the right MessageDescriptor at runtime.

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Construct a new builder with default settings.

Source

pub fn descriptor_pool(self, expr: impl Into<String>) -> Self

Use a user-managed DescriptorPool for runtime descriptor lookup. The argument is a Rust expression yielding &buffa_reflect::DescriptorPool (e.g. "crate::DESCRIPTOR_POOL").

Source

pub fn file_descriptor_set_bytes(self, expr: impl Into<String>) -> Self

Embed the descriptor-set bytes directly. The argument is a Rust expression yielding &[u8], typically "crate::FILE_DESCRIPTOR_SET_BYTES" paired with include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin")).

Source

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

Override where the descriptor-set artifact is written. Defaults to <OUT_DIR>/file_descriptor_set.bin.

Source

pub fn files(self, files: &[impl AsRef<Path>]) -> Self

.proto files to compile. Same semantics as buffa_build::Config::files.

Source

pub fn includes(self, includes: &[impl AsRef<Path>]) -> Self

Include directories searched by protoc.

Source

pub fn use_buf(self) -> Self

Use buf build --as-file-descriptor-set instead of protoc.

Source

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

Use a precompiled descriptor-set file. Skips invoking protoc/buf. The file must contain a serialized google.protobuf.FileDescriptorSet.

Source

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

Override the output directory (defaults to $OUT_DIR).

Source

pub fn type_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self

Pass a type_attribute through to buffa-build.

Source

pub fn field_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self

Pass a field_attribute through to buffa-build.

Source

pub fn message_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self

Pass a message_attribute through to buffa-build (struct-only).

Source

pub fn enum_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self

Pass an enum_attribute through to buffa-build (enum-only).

Source

pub fn extern_path( self, proto_path: impl Into<String>, rust_path: impl Into<String>, ) -> Self

Map a proto path prefix to an external Rust module. Forwarded to buffa_build::Config::extern_path.

Source

pub fn use_bytes_type_in(self, paths: &[impl AsRef<str>]) -> Self

Mark bytes fields under the given proto-path prefixes as bytes::Bytes-typed.

Source

pub fn generate_views(self, enabled: bool) -> Self

Toggle generation of borrowed view types. Defaults to buffa-build’s own default (currently true).

Source

pub fn generate_json(self, enabled: bool) -> Self

Toggle proto3 JSON serde derives.

Source

pub fn generate_text(self, enabled: bool) -> Self

Toggle textproto support.

Source

pub fn generate_arbitrary(self, enabled: bool) -> Self

Toggle arbitrary::Arbitrary derives.

Source

pub fn preserve_unknown_fields(self, enabled: bool) -> Self

Toggle unknown-field preservation.

Source

pub fn strict_utf8_mapping(self, enabled: bool) -> Self

Honor features.utf8_validation = NONE by mapping such strings to bytes — see buffa_build::Config::strict_utf8_mapping.

Source

pub fn allow_message_set(self, enabled: bool) -> Self

Permit message_set_wire_format = true on input messages.

Source

pub fn include_file(self, name: impl Into<String>) -> Self

Emit a per-package include-file alongside the per-proto outputs.

Source

pub fn generate_view_reflection(self, enabled: bool) -> Self

Emit impl ReflectMessageView<'a> blocks for every generated view type into OUT_DIR/<view_reflection_include_file>. The downstream user include!s the file once after their buffa::include_proto!(...) invocation.

Default: true when the file_descriptor_set_bytes binding is configured (the only binding the emitter can plumb into a OnceLock initializer); false otherwise. Override explicitly to opt out.

Source

pub fn view_reflection_include_file(self, name: impl Into<String>) -> Self

Override the file name of the view-reflection include file. Default: _reflect_views.rs.

Source

pub fn view_reflection_root_path(self, path: impl Into<String>) -> Self

Override the Rust module path under which the generated view types live. Default: crate::__buffa::view, matching the buffa::include_proto! invocation at the crate root.

Override when the consumer wraps include_proto! inside a non-root module, e.g. pub mod my_pkg { buffa::include_proto!(...); } — set this to crate::my_pkg::__buffa::view.

Source

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

Compile the configured .proto files.

§Errors

See Error for the failure modes — most user errors are an unconfigured descriptor binding, a missing OUT_DIR, or protoc/buf invocation failure.

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.