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
impl Builder
Sourcepub fn descriptor_pool(self, expr: impl Into<String>) -> Self
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").
Sourcepub fn file_descriptor_set_bytes(self, expr: impl Into<String>) -> Self
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")).
Sourcepub fn file_descriptor_set_path(self, path: impl Into<PathBuf>) -> Self
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.
Sourcepub fn files(self, files: &[impl AsRef<Path>]) -> Self
pub fn files(self, files: &[impl AsRef<Path>]) -> Self
.proto files to compile. Same semantics as
buffa_build::Config::files.
Sourcepub fn includes(self, includes: &[impl AsRef<Path>]) -> Self
pub fn includes(self, includes: &[impl AsRef<Path>]) -> Self
Include directories searched by protoc.
Sourcepub fn descriptor_set(self, path: impl Into<PathBuf>) -> Self
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.
Sourcepub fn out_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn out_dir(self, dir: impl Into<PathBuf>) -> Self
Override the output directory (defaults to $OUT_DIR).
Sourcepub fn type_attribute(
self,
path: impl Into<String>,
attr: impl Into<String>,
) -> Self
pub fn type_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self
Pass a type_attribute through to buffa-build.
Sourcepub fn field_attribute(
self,
path: impl Into<String>,
attr: impl Into<String>,
) -> Self
pub fn field_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self
Pass a field_attribute through to buffa-build.
Sourcepub fn message_attribute(
self,
path: impl Into<String>,
attr: impl Into<String>,
) -> Self
pub fn message_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self
Pass a message_attribute through to buffa-build (struct-only).
Sourcepub fn enum_attribute(
self,
path: impl Into<String>,
attr: impl Into<String>,
) -> Self
pub fn enum_attribute( self, path: impl Into<String>, attr: impl Into<String>, ) -> Self
Pass an enum_attribute through to buffa-build (enum-only).
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 path prefix to an external Rust module. Forwarded to
buffa_build::Config::extern_path.
Sourcepub fn use_bytes_type_in(self, paths: &[impl AsRef<str>]) -> Self
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.
Sourcepub fn generate_views(self, enabled: bool) -> Self
pub fn generate_views(self, enabled: bool) -> Self
Toggle generation of borrowed view types. Defaults to buffa-build’s
own default (currently true).
Sourcepub fn generate_json(self, enabled: bool) -> Self
pub fn generate_json(self, enabled: bool) -> Self
Toggle proto3 JSON serde derives.
Sourcepub fn generate_text(self, enabled: bool) -> Self
pub fn generate_text(self, enabled: bool) -> Self
Toggle textproto support.
Sourcepub fn generate_arbitrary(self, enabled: bool) -> Self
pub fn generate_arbitrary(self, enabled: bool) -> Self
Toggle arbitrary::Arbitrary derives.
Sourcepub fn preserve_unknown_fields(self, enabled: bool) -> Self
pub fn preserve_unknown_fields(self, enabled: bool) -> Self
Toggle unknown-field preservation.
Sourcepub fn strict_utf8_mapping(self, enabled: bool) -> Self
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.
Sourcepub fn allow_message_set(self, enabled: bool) -> Self
pub fn allow_message_set(self, enabled: bool) -> Self
Permit message_set_wire_format = true on input messages.
Sourcepub fn include_file(self, name: impl Into<String>) -> Self
pub fn include_file(self, name: impl Into<String>) -> Self
Emit a per-package include-file alongside the per-proto outputs.
Sourcepub fn generate_view_reflection(self, enabled: bool) -> Self
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.
Sourcepub fn view_reflection_include_file(self, name: impl Into<String>) -> Self
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.
Sourcepub fn view_reflection_root_path(self, path: impl Into<String>) -> Self
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.