From 30b8036efafe4820fb11b718c1fb013e01f0039b Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 4 Feb 2017 11:52:48 +0100 Subject: [PATCH] Remove ser::Iterator --- serde/src/ser/impls.rs | 30 ------------------------------ serde/src/ser/mod.rs | 27 --------------------------- 2 files changed, 57 deletions(-) diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index c23afdbc..61f2c1fd 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -66,9 +66,6 @@ use super::{ #[cfg(any(feature = "std", feature = "unstable"))] use super::Error; -#[cfg(feature = "unstable")] -use super::Iterator; - /////////////////////////////////////////////////////////////////////////////// macro_rules! impl_visit { @@ -220,33 +217,6 @@ array_impls!(32); /////////////////////////////////////////////////////////////////////////////// -#[cfg(feature = "unstable")] -impl<'a, I> Serialize for Iterator - where I: IntoIterator, ::Item: Serialize -{ - #[inline] - fn serialize(&self, serializer: S) -> Result - where S: Serializer, - { - // FIXME: use specialization to prevent invalidating the object in case of clonable iterators? - let iter = match self.data.borrow_mut().take() { - Some(iter) => iter.into_iter(), - None => return Err(Error::custom("Iterator used twice")), - }; - let size = match iter.size_hint() { - (lo, Some(hi)) if lo == hi => Some(lo), - _ => None, - }; - let mut seq = try!(serializer.serialize_seq(size)); - for e in iter { - try!(seq.serialize_element(&e)); - } - seq.end() - } -} - -/////////////////////////////////////////////////////////////////////////////// - macro_rules! serialize_seq { () => { #[inline] diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index a1528839..c7635c34 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -98,9 +98,6 @@ use std::error; #[cfg(not(feature = "std"))] use error; -#[cfg(feature = "unstable")] -use core::cell::RefCell; - use core::fmt::Display; use core::iter::IntoIterator; @@ -839,30 +836,6 @@ pub trait SerializeStructVariant { fn end(self) -> Result; } -/// A wrapper type for iterators that implements `Serialize` for iterators whose -/// items implement `Serialize`. Don't use multiple times. Create new versions -/// of this with the `serde::ser::iterator` function every time you want to -/// serialize an iterator. -#[cfg(feature = "unstable")] -pub struct Iterator - where ::Item: Serialize, - I: IntoIterator -{ - data: RefCell>, -} - -/// Create a wrapper type that can be passed to any function expecting a -/// `Serialize` and will serialize the given iterator as a sequence. -#[cfg(feature = "unstable")] -pub fn iterator(iter: I) -> Iterator - where ::Item: Serialize, - I: IntoIterator -{ - Iterator { - data: RefCell::new(Some(iter)), - } -} - fn iterator_len_hint(iter: &I) -> Option { match iter.size_hint() { (lo, Some(hi)) if lo == hi => Some(lo),