pub trait ProtoString:
Clone
+ PartialEq
+ Default
+ Debug
+ Send
+ Sync
+ AsRef<str>
+ From<String>
+ for<'a> From<&'a str> { }Expand description
The bound generated code places on the Rust type used for a proto string
field. You neither implement nor name this trait by hand — a blanket impl
covers every conforming type, and a forthcoming string_type knob in
buffa_build selects the concrete type at code-generation time.
buffa generates String by default. The knob will be able to substitute a
small-string-optimized type — such as smol_str::SmolStr,
ecow::EcoString, or compact_str::CompactString (each behind the matching
buffa feature) — for read-mostly schemas where String’s growable buffer
is unnecessary.
The bounds are exactly what generated code requires of a string field:
Clone + PartialEq + Default + Debug— for the#[derive(...)]and the hand-writtenDebugimpl on message structs, and forclear()(which resets the field toDefaultrather than relying on aString-specificclear, since the small-string types may be immutable).Send + Sync— so a message owning such a field staysSend + Sync; without this bound an exotic string type could silently make every containing message thread-unsafe.AsRef<str>— the encoder borrows the field as&str;encode_stringandstring_encoded_lentake&str.From<String>andFrom<&str>— used by the decode path (decode_string_to) and (once the knob lands) the view→owned conversion to construct the field from freshly decoded text.
For the default String representation every conversion is the identity, so
the generic path costs nothing relative to the specialized one.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".