#[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; view types keep borrowing &[u8], and map bytes values
follow the same rules as the string path.
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
- A foreign custom type used as a
repeatedelement fails to compile (the emittedReflectElement/ProtoElemJsonimpls violate the orphan rule). Wrap it in a crate-local newtype for that case; singular / optional / oneof uses work with a foreign type directly. - A
Customrule does not apply tomap<K, bytes>values — they stayVec<u8>. Only the built-inBytesapplies to map values. - A path that does not parse as a Rust type surfaces as
CodeGenError::InvalidTypePathat generation (.compile()) time. - The per-element impls are deduplicated within a single generation, but
the same crate-local type used as a
repeatedelement across two separatecompile()invocations in one crate emits the impl twice (a duplicate-implE0119). Generate from a singlecompile(), or use distinct element types.