#[non_exhaustive]pub enum StringRepr {
String,
Custom(String),
}Expand description
The Rust type a proto string field maps to in generated owned structs.
The default is String.
Custom substitutes any type named by its
fully-qualified Rust path — for example ::smol_str::SmolStr,
::ecow::EcoString, or ::compact_str::CompactString for read-mostly
schemas — that satisfies the buffa::ProtoString bound. The downstream crate
must itself depend on the crate providing that type (buffa does not re-export
it).
Select a representation through buffa_build’s string_type /
string_type_custom builder methods. The wire format is identical regardless
of representation — only the in-memory owned type changes, and view types
keep borrowing &str. A rule that matches a map field applies to its
string key and its string value.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
String
::buffa::alloc::string::String — growable and mutable (the default).
Custom(String)
A custom type named by its fully-qualified Rust path (e.g.
"::smol_str::SmolStr"). Must satisfy buffa::ProtoString and be
provided by a crate the downstream depends on.
§Limitations
- With
generate_reflection_vtable, or any reflection with message cleanup, a foreign custom type used as arepeatedelement or as amapkey or value fails to compile (the emittedReflectElement/InspectElement/ReflectMapKeyimpl violates 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 custom type used as a
mapkey must implementHash + EqforMapRepr::HashMap, orOrdforMapRepr::BTreeMap. - With
generate_json, a custom type on anoptional,repeatedor oneof field, or used as amapkey or value, must implementserde::Serializeandserde::Deserialize. A singular field withoutoptionalneeds noserdeimpl, and neither does a type listed injson_policy_types, whose JSON goes through itsProtoStringJsonpolicy in every generated JSON position; codegen emits no JSON trait impl for such a type, so under JSON it may be foreign. - 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 ormapkey or value across two separatecompile()invocations in one crate emits the impl twice (a duplicate-implE0119) when those runs generate vtable reflection or reflection with message cleanup (JSON emits no string element impl). Generate from a singlecompile(), use distinct element types, or disable generated integrations and provide them once in the defining crate.