Unignore Serializer::serialize_map example
This commit is contained in:
parent
ad249c7fac
commit
8aa630ea48
@ -690,12 +690,42 @@ pub trait Serializer: Sized {
|
||||
/// be computable before the map is iterated. Some serializers only support
|
||||
/// maps whose length is known up front.
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// let mut map = serializer.serialize_map(Some(self.len()))?;
|
||||
/// for (k, v) in self {
|
||||
/// map.serialize_entry(k, v)?;
|
||||
/// ```rust
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # 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>;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user