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§
Required Methods§
sourcefn encode_key<T: IntoStream<'en> + 'en>(
&mut self,
key: T
) -> Result<(), Self::Error>
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
.
sourcefn encode_value<T: IntoStream<'en> + 'en>(
&mut self,
value: T
) -> Result<(), Self::Error>
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.
Provided Methods§
sourcefn encode_entry<K: IntoStream<'en> + 'en, V: IntoStream<'en> + 'en>(
&mut self,
key: K,
value: V
) -> Result<(), Self::Error>
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.