#[non_exhaustive]pub enum BytesRepr {
Vec,
Bytes,
Custom(String),
}Expand description
The Rust type a proto bytes field maps to in generated owned structs.
The default is Vec (Vec<u8>). Bytes
uses bytes::Bytes, which decodes zero-copy from a
Bytes-backed buffer. Custom substitutes any type
named by its fully-qualified Rust path that satisfies the buffa::ProtoBytes
bound; the downstream crate must itself depend on the providing crate.
Select a representation through buffa_build’s bytes_type /
bytes_type_custom builder methods (or the legacy use_bytes_type, which
selects Bytes). The wire format is identical regardless
of representation, and view types keep borrowing &[u8]. A rule that
matches a map field applies to its bytes value. One map shape keeps
Vec<u8> values whatever rule matches: a map whose string key is mapped
to bytes by strict_utf8_mapping
(utf8_validation = NONE on the key) and whose value is bytes.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Vec
::buffa::alloc::vec::Vec<u8> — growable and mutable (the default).
Bytes
::buffa::bytes::Bytes — reference-counted, immutable, decodes zero-copy
from a Bytes-backed buffer.
Custom(String)
A custom type named by its fully-qualified Rust path. Must satisfy
buffa::ProtoBytes and be provided by a crate the downstream depends on.
§Limitations
- Under
generate_json(for a type not listed injson_policy_types),generate_reflection_vtable, or any reflection with message cleanup, a foreign custom type used as arepeatedelement fails to compile (the emittedProtoElemJson/ReflectElement/InspectElementimpls violate the orphan rule). Wrap it in a crate-local newtype, or setCodeGenConfig::emit_custom_type_implstofalsewhen the defining crate supplies those integrations. Singular / optional / oneof uses work with a foreign type directly. - A
Customrule applies tomap<K, bytes>values, asBytesdoes, with the same element impls and the same crate-local requirement. - A type listed in
json_policy_typesgets noProtoElemJsonimpl: itsrepeatedelements andmapvalues go through buffa’s policy helpers, so with JSON alone it may be defined, together with itsProtoBytesandProtoBytesJsonimpls, in another crate. Vtable reflection still emitsReflectElement, and reflection with message cleanupInspectElement, for it. - A type that is not a type path like
crate::Name(for example_,()or&'static [u8]) surfaces asCodeGenError::InvalidTypePathat generation (.compile()) time. Associated type projections and parenthesized type paths are supported. - The per-element impls are deduplicated within a single generation, but
the same crate-local type used as a
repeatedelement ormapvalue across two separatecompile()invocations in one crate emits the impl twice (a duplicate-implE0119), unless neither run emits one: the type is listed injson_policy_typesand the runs generate no vtable reflection and no reflection with message cleanup. Otherwise generate from a singlecompile(), use distinct element types, or disable generated integrations and provide them once in the defining crate.