rename IteratorSerializer to Iterator

This commit is contained in:
Oliver Schneider 2017-01-12 17:29:04 +01:00
parent b860d3cb1f
commit 8c576fe9fb
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46
2 changed files with 13 additions and 11 deletions

View File

@ -73,7 +73,7 @@ use super::{
};
#[cfg(feature = "unstable")]
use super::IteratorSerializer;
use super::Iterator;
///////////////////////////////////////////////////////////////////////////////
@ -225,8 +225,8 @@ array_impls!(32);
///////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "unstable")]
impl<'a, I> Serialize for IteratorSerializer<I>
where I: Iterator, <I as Iterator>::Item: Serialize
impl<'a, I> Serialize for Iterator<I>
where I: iter::Iterator, <I as iter::Iterator>::Item: Serialize
{
#[inline]
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?
let iter = match self.0.borrow_mut().take() {
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() {
(lo, Some(hi)) if lo == hi => Some(lo),

View File

@ -22,6 +22,8 @@ use collections::String;
use core::marker::PhantomData;
#[cfg(feature = "unstable")]
use core::cell::RefCell;
#[cfg(feature = "unstable")]
use core::iter;
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
/// every time you want to serialize an iterator.
#[cfg(feature = "unstable")]
pub struct IteratorSerializer<I>(RefCell<Option<I>>)
where <I as Iterator>::Item: Serialize,
I: Iterator;
pub struct Iterator<I>(RefCell<Option<I>>)
where <I as iter::Iterator>::Item: Serialize,
I: iter::Iterator;
/// Creates a temporary 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<I>(iter: I) -> IteratorSerializer<I>
where <I as Iterator>::Item: Serialize,
I: Iterator
pub fn iterator<I>(iter: I) -> Iterator<I>
where <I as iter::Iterator>::Item: Serialize,
I: iter::Iterator
{
IteratorSerializer(RefCell::new(Some(iter)))
Iterator(RefCell::new(Some(iter)))
}