#[non_exhaustive]pub struct CodeGenConfig {
pub generate_views: bool,
pub preserve_unknown_fields: bool,
pub generate_json: bool,
pub generate_arbitrary: bool,
pub extern_paths: Vec<(String, String)>,
pub bytes_fields: Vec<String>,
pub strict_utf8_mapping: bool,
}Expand description
Configuration for code generation.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.generate_views: boolWhether to generate borrowed view types (MyMessageView<'a>) in
addition to owned types.
preserve_unknown_fields: boolWhether to preserve unknown fields (default: true).
generate_json: boolWhether to derive serde::Serialize / serde::Deserialize on
generated message structs and enum types, and emit #[serde(with = "...")]
attributes for proto3 JSON’s special scalar encodings (int64 as quoted
string, bytes as base64, etc.).
When this is true, the downstream crate must depend on serde and
must enable the buffa/json feature for the runtime helpers.
Oneof fields use #[serde(flatten)] with custom Serialize /
Deserialize impls so that each variant appears as a top-level
JSON field (proto3 JSON inline oneof encoding).
generate_arbitrary: boolWhether to emit #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
on generated message structs and enum types.
When this is true, the downstream crate must add arbitrary as an
optional dependency and enable the buffa/arbitrary feature.
extern_paths: Vec<(String, String)>External type path mappings.
Each entry maps a fully-qualified protobuf path prefix (e.g.,
".my.common") to a Rust module path (e.g., "::common_protos").
Types under the proto prefix will reference the extern Rust path
instead of being generated, allowing shared proto packages to be
compiled once in a dedicated crate and referenced from others.
Well-known types (google.protobuf.*) are automatically mapped to
::buffa_types::google::protobuf::* without needing an explicit
entry here. To override with a custom implementation, add an
extern_path for .google.protobuf pointing to your crate.
bytes_fields: Vec<String>Fully-qualified proto field paths whose bytes fields should use
bytes::Bytes instead of Vec<u8>.
Each entry is a proto path prefix (e.g., ".my.pkg.MyMessage.data" for
a specific field, or "." for all bytes fields). The path is matched
as a prefix, so "." applies to every bytes field in every message.
strict_utf8_mapping: boolHonor features.utf8_validation = NONE by emitting Vec<u8> / &[u8]
for such string fields instead of String / &str.
When false (the default), buffa emits String for all string fields
and validates UTF-8 on decode — stricter than proto2 requires, but
ergonomic and safe.
When true, string fields with utf8_validation = NONE (all proto2
strings by default, and editions fields that opt into NONE) become
Vec<u8> / &[u8]. Decode skips validation; the caller decides at the
call site whether to std::str::from_utf8 (checked) or
from_utf8_unchecked (trusted-input fast path). This is the only
sound Rust mapping when strings may actually contain non-UTF-8 bytes.
This is a breaking change for proto2 — enable only for new code or when profiling identifies UTF-8 validation as a bottleneck.
Trait Implementations§
Source§impl Clone for CodeGenConfig
impl Clone for CodeGenConfig
Source§fn clone(&self) -> CodeGenConfig
fn clone(&self) -> CodeGenConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more