rename IteratorSerializer to Iterator

This commit is contained in:
Oliver Schneider
2017-01-12 17:29:04 +01:00
parent b860d3cb1f
commit 8c576fe9fb
2 changed files with 13 additions and 11 deletions
+4 -4
View File
@@ -73,7 +73,7 @@ use super::{
}; };
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
use super::IteratorSerializer; use super::Iterator;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -225,8 +225,8 @@ array_impls!(32);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
impl<'a, I> Serialize for IteratorSerializer<I> impl<'a, I> Serialize for Iterator<I>
where I: Iterator, <I as Iterator>::Item: Serialize where I: iter::Iterator, <I as iter::Iterator>::Item: Serialize
{ {
#[inline] #[inline]
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
@@ -235,7 +235,7 @@ impl<'a, I> Serialize for IteratorSerializer<I>
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators? // FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
let iter = match self.0.borrow_mut().take() { let iter = match self.0.borrow_mut().take() {
Some(iter) => iter, Some(iter) => iter,
None => return Err(S::Error::custom("IteratorSerializer used twice")), None => return Err(S::Error::custom("Iterator used twice")),
}; };
let size = match iter.size_hint() { let size = match iter.size_hint() {
(lo, Some(hi)) if lo == hi => Some(lo), (lo, Some(hi)) if lo == hi => Some(lo),
+9 -7
View File
@@ -22,6 +22,8 @@ use collections::String;
use core::marker::PhantomData; use core::marker::PhantomData;
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
use core::cell::RefCell; use core::cell::RefCell;
#[cfg(feature = "unstable")]
use core::iter;
pub mod impls; pub mod impls;
@@ -421,16 +423,16 @@ pub trait Serializer {
/// `Serialize`. Don't use multiple times. Create new versions of this with the `iterator` function /// `Serialize`. Don't use multiple times. Create new versions of this with the `iterator` function
/// every time you want to serialize an iterator. /// every time you want to serialize an iterator.
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub struct IteratorSerializer<I>(RefCell<Option<I>>) pub struct Iterator<I>(RefCell<Option<I>>)
where <I as Iterator>::Item: Serialize, where <I as iter::Iterator>::Item: Serialize,
I: Iterator; I: iter::Iterator;
/// Creates a temporary type that can be passed to any function expecting a `Serialize` and will /// Creates a temporary type that can be passed to any function expecting a `Serialize` and will
/// serialize the given iterator as a sequence /// serialize the given iterator as a sequence
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub fn iterator<I>(iter: I) -> IteratorSerializer<I> pub fn iterator<I>(iter: I) -> Iterator<I>
where <I as Iterator>::Item: Serialize, where <I as iter::Iterator>::Item: Serialize,
I: Iterator I: iter::Iterator
{ {
IteratorSerializer(RefCell::new(Some(iter))) Iterator(RefCell::new(Some(iter)))
} }