Skip to main content

TextFormat

Trait TextFormat 

Source
pub trait TextFormat: Message {
    // Required methods
    fn encode_text(&self, enc: &mut TextEncoder<'_>) -> Result;
    fn merge_text(
        &mut self,
        dec: &mut TextDecoder<'_>,
    ) -> Result<(), ParseError>;
}
Available on crate feature 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§

Source

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.

Source

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. Unknown names either skip_value or fail with unknown_field, depending on codegen configuration.

§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", so this trait is not object safe.

Implementors§