#[non_exhaustive]pub struct CodeGenConfig {Show 14 fields
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,
pub allow_message_set: bool,
pub generate_text: bool,
pub emit_register_fn: bool,
pub type_attributes: Vec<(String, String)>,
pub field_attributes: Vec<(String, String)>,
pub message_attributes: Vec<(String, String)>,
pub enum_attributes: Vec<(String, String)>,
}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.
allow_message_set: boolPermit option message_set_wire_format = true on input messages.
MessageSet is a legacy Google-internal wire format that wraps each
extension in a group structure instead of using regular field tags.
When false (the default), encountering such a message is a codegen
error — the flag exists to make MessageSet use explicit, since the
format is obsolete outside of interop with very old Google protos.
generate_text: boolWhether to emit impl buffa::text::TextFormat on generated message
structs for textproto (human-readable text format) encoding/decoding.
When this is true, the downstream crate must enable the buffa/text
feature for the runtime encoder/decoder.
emit_register_fn: boolWhether the per-package .mod.rs stitcher emits
__buffa::register_types(&mut TypeRegistry).
Default true. The fn aggregates Any type entries and extension
entries for every message in the package. Set to false for
crates that don’t use extensions/Any, or that hand-roll
registration (e.g. buffa-types’ register_wkt_types, which
knows the JSON-Any is_wkt special-casing the generic fn does
not). The per-message __*_JSON_ANY / __*_TEXT_ANY consts are
still emitted; only the aggregating fn is suppressed.
type_attributes: Vec<(String, String)>Custom attributes to inject on generated types (messages and enums).
Each entry is (proto_path, attribute). The proto_path is matched
as a prefix against the fully-qualified proto name: "." applies to
all types, ".my.pkg" to types in that package, ".my.pkg.MyMessage"
to a specific type. The attribute is a raw Rust attribute string
(e.g., "#[derive(serde::Serialize)]").
field_attributes: Vec<(String, String)>Custom attributes to inject on generated struct fields.
Each entry is (proto_path, attribute). The proto_path is matched
as a prefix against the fully-qualified field path (e.g.,
".my.pkg.MyMessage.my_field"). "." applies to all fields.
message_attributes: Vec<(String, String)>Custom attributes to inject on generated message structs only (not enums).
Same path-matching semantics as type_attributes, but only applied to
message structs, not enum types. Useful for struct-only attributes like
#[serde(default)].
enum_attributes: Vec<(String, String)>Custom attributes to inject on generated enum types only (not messages).
Same path-matching semantics as type_attributes, but only applied to
enum types. Useful for enum-only attributes like
#[derive(strum::EnumIter)] when the user does not want to apply the
same attribute to every message in the matched scope.
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