mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-21 01:31:09 +00:00
Unignore Serializer::serialize_map example
This commit is contained in:
+35
-5
@@ -690,12 +690,42 @@ pub trait Serializer: Sized {
|
|||||||
/// be computable before the map is iterated. Some serializers only support
|
/// be computable before the map is iterated. Some serializers only support
|
||||||
/// maps whose length is known up front.
|
/// maps whose length is known up front.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
/// let mut map = serializer.serialize_map(Some(self.len()))?;
|
/// # use std::marker::PhantomData;
|
||||||
/// for (k, v) in self {
|
/// #
|
||||||
/// map.serialize_entry(k, v)?;
|
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||||
|
/// #
|
||||||
|
/// # impl<K, V> HashMap<K, V> {
|
||||||
|
/// # fn len(&self) -> usize {
|
||||||
|
/// # unimplemented!()
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
||||||
|
/// # type Item = (&'a K, &'a V);
|
||||||
|
/// # type IntoIter = Box<Iterator<Item = (&'a K, &'a V)>>;
|
||||||
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
|
/// # unimplemented!()
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// use serde::{Serialize, Serializer};
|
||||||
|
/// use serde::ser::SerializeMap;
|
||||||
|
///
|
||||||
|
/// impl<K, V> Serialize for HashMap<K, V>
|
||||||
|
/// where K: Serialize,
|
||||||
|
/// V: Serialize
|
||||||
|
/// {
|
||||||
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
/// where S: Serializer
|
||||||
|
/// {
|
||||||
|
/// let mut map = serializer.serialize_map(Some(self.len()))?;
|
||||||
|
/// for (k, v) in self {
|
||||||
|
/// map.serialize_entry(k, v)?;
|
||||||
|
/// }
|
||||||
|
/// map.end()
|
||||||
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// map.end()
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error>;
|
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user