Add a collect_seq example

This commit is contained in:
David Tolnay 2017-04-13 14:19:17 -07:00
parent 8d1f882512
commit 41488252ff
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -881,6 +881,22 @@ pub trait Serializer: Sized {
/// using [`serialize_seq`]. Implementors should not need to override this
/// method.
///
/// ```rust
/// use serde::{Serialize, Serializer};
///
/// struct SecretlyOneHigher {
/// data: Vec<i32>,
/// }
///
/// impl Serialize for SecretlyOneHigher {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where S: Serializer
/// {
/// serializer.collect_seq(self.data.iter().map(|x| x + 1))
/// }
/// }
/// ```
///
/// [`serialize_seq`]: #tymethod.serialize_seq
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
where