Trait destream::en::EncodeMap

source ·
pub trait EncodeMap<'en> {
    type Ok: Stream + Send + Unpin + 'en;
    type Error: Error + Send + Unpin + 'en;

    // Required methods
    fn encode_key<T: IntoStream<'en> + 'en>(
        &mut self,
        key: T
    ) -> Result<(), Self::Error>;
    fn encode_value<T: IntoStream<'en> + 'en>(
        &mut self,
        value: T
    ) -> Result<(), Self::Error>;
    fn end(self) -> Result<Self::Ok, Self::Error>;

    // Provided method
    fn encode_entry<K: IntoStream<'en> + 'en, V: IntoStream<'en> + 'en>(
        &mut self,
        key: K,
        value: V
    ) -> Result<(), Self::Error> { ... }
}
Expand description

Returned from Encoder::encode_map.

Required Associated Types§

source

type Ok: Stream + Send + Unpin + 'en

Must match the Ok type of the parent Encoder.

source

type Error: Error + Send + Unpin + 'en

Must match the Error type of the parent Encoder.

Required Methods§

source

fn encode_key<T: IntoStream<'en> + 'en>( &mut self, key: T ) -> Result<(), Self::Error>

Encode a map key.

If possible, ToStream implementations are encouraged to use encode_entry instead as it may be implemented more efficiently in some formats compared to a pair of calls to encode_key and encode_value.

source

fn encode_value<T: IntoStream<'en> + 'en>( &mut self, value: T ) -> Result<(), Self::Error>

Encode a map value.

Panics

Calling encode_value before encode_key is incorrect and is allowed to panic or produce bogus results.

source

fn end(self) -> Result<Self::Ok, Self::Error>

Finish encoding the map.

Provided Methods§

source

fn encode_entry<K: IntoStream<'en> + 'en, V: IntoStream<'en> + 'en>( &mut self, key: K, value: V ) -> Result<(), Self::Error>

Encode a map entry consisting of a key and a value.

The default implementation delegates to encode_key and encode_value. This is appropriate for encoders that do not care about performance or are not able to optimize encode_entry any further.

Object Safety§

This trait is not object safe.

Implementors§