mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-03 07:45:38 +00:00
Remove ser::Iterator
This commit is contained in:
parent
89bb16da6b
commit
30b8036efa
@ -66,9 +66,6 @@ use super::{
|
|||||||
#[cfg(any(feature = "std", feature = "unstable"))]
|
#[cfg(any(feature = "std", feature = "unstable"))]
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use super::Iterator;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! impl_visit {
|
macro_rules! impl_visit {
|
||||||
@ -220,33 +217,6 @@ array_impls!(32);
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
impl<'a, I> Serialize for Iterator<I>
|
|
||||||
where I: IntoIterator, <I as IntoIterator>::Item: Serialize
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
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 {
|
macro_rules! serialize_seq {
|
||||||
() => {
|
() => {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -98,9 +98,6 @@ use std::error;
|
|||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use error;
|
use error;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use core::cell::RefCell;
|
|
||||||
|
|
||||||
use core::fmt::Display;
|
use core::fmt::Display;
|
||||||
use core::iter::IntoIterator;
|
use core::iter::IntoIterator;
|
||||||
|
|
||||||
@ -839,30 +836,6 @@ pub trait SerializeStructVariant {
|
|||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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<I>
|
|
||||||
where <I as IntoIterator>::Item: Serialize,
|
|
||||||
I: IntoIterator
|
|
||||||
{
|
|
||||||
data: RefCell<Option<I>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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<I>(iter: I) -> Iterator<I>
|
|
||||||
where <I as IntoIterator>::Item: Serialize,
|
|
||||||
I: IntoIterator
|
|
||||||
{
|
|
||||||
Iterator {
|
|
||||||
data: RefCell::new(Some(iter)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn iterator_len_hint<I: Iterator>(iter: &I) -> Option<usize> {
|
fn iterator_len_hint<I: Iterator>(iter: &I) -> Option<usize> {
|
||||||
match iter.size_hint() {
|
match iter.size_hint() {
|
||||||
(lo, Some(hi)) if lo == hi => Some(lo),
|
(lo, Some(hi)) if lo == hi => Some(lo),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user