pub trait TextFormat: Message {
// Required methods
fn encode_text(&self, enc: &mut TextEncoder<'_>) -> Result;
fn merge_text(
&mut self,
dec: &mut TextDecoder<'_>,
) -> Result<(), ParseError>;
}text only.Expand description
Textproto serialization for a Message type.
Implemented by generated code when the text feature is enabled in
codegen. Hand-implementation is possible but — as with
Message itself — discouraged outside of tests.
The trait is deliberately minimal: one method per direction, taking a mutable encoder/decoder. The encoder/decoder own all formatting and parsing state; the impl just dispatches on field names.
Required Methods§
Sourcefn encode_text(&self, enc: &mut TextEncoder<'_>) -> Result
fn encode_text(&self, enc: &mut TextEncoder<'_>) -> Result
Write this message’s fields to enc.
Implementations call TextEncoder::write_field_name followed by
the appropriate write_* value method for each set field. Unset
singular fields and empty repeated fields are skipped.
§Errors
Propagates core::fmt::Error from the encoder’s sink. When writing
to a String, this is always Ok.
Sourcefn merge_text(&mut self, dec: &mut TextDecoder<'_>) -> Result<(), ParseError>
fn merge_text(&mut self, dec: &mut TextDecoder<'_>) -> Result<(), ParseError>
Merge fields from dec into this message.
Implementations loop on TextDecoder::read_field_name until it
returns None, dispatching each name to the matching read_* call.
Generated implementations reject unknown names with
unknown_field. Hand-written
implementations can explicitly call
skip_value when lenient parsing is needed.
§Errors
Any ParseError from the decoder.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".