Trait serde::ser::SerializeMap
[−]
[src]
pub trait SerializeMap {
type Ok;
type Error: Error;
fn serialize_key<T: ?Sized + Serialize>(
&mut self,
key: &T
) -> Result<(), Self::Error>;
fn serialize_value<T: ?Sized + Serialize>(
&mut self,
value: &T
) -> Result<(), Self::Error>;
fn end(self) -> Result<Self::Ok, Self::Error>;
fn serialize_entry<K: ?Sized + Serialize, V: ?Sized + Serialize>(
&mut self,
key: &K,
value: &V
) -> Result<(), Self::Error> { ... }
}Returned from Serializer::serialize_map.
let mut map = serializer.serialize_map(Some(self.len()))?; for (k, v) in self { map.serialize_entry(k, v)?; } map.end()
Associated Types
type Ok
Must match the Ok type of our Serializer.
type Error: Error
Must match the Error type of our Serializer.
Required Methods
fn serialize_key<T: ?Sized + Serialize>(
&mut self,
key: &T
) -> Result<(), Self::Error>
&mut self,
key: &T
) -> Result<(), Self::Error>
Serialize a map key.
fn serialize_value<T: ?Sized + Serialize>(
&mut self,
value: &T
) -> Result<(), Self::Error>
&mut self,
value: &T
) -> Result<(), Self::Error>
Serialize a map value.
fn end(self) -> Result<Self::Ok, Self::Error>
Finish serializing a map.
Provided Methods
fn serialize_entry<K: ?Sized + Serialize, V: ?Sized + Serialize>(
&mut self,
key: &K,
value: &V
) -> Result<(), Self::Error>
&mut self,
key: &K,
value: &V
) -> Result<(), Self::Error>
Serialize a map entry consisting of a key and a value.
Some Serialize types are not able to hold a key and value in memory at
the same time so SerializeMap implementations are required to support
serialize_key and serialize_value individually. The
serialize_entry method allows serializers to optimize for the case
where key and value are both available. Serialize implementations are
encouraged to use serialize_entry if possible.
The default implementation delegates to serialize_key and
serialize_value. This is appropriate for serializers that do not care
about performance or are not able to optimize serialize_entry any
better than this.
Implementors
impl<Ok, E> SerializeMap for Impossible<Ok, E> where
E: Error,