Implement Clone for the value deserializers

This commit is contained in:
David Tolnay 2017-04-13 11:11:09 -07:00
parent 7d0a38270d
commit aef136934b
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -61,7 +61,7 @@ impl<'de, E> IntoDeserializer<'de, E> for ()
}
/// A helper deserializer that deserializes a `()`.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct UnitDeserializer<E> {
marker: PhantomData<E>,
}
@ -95,7 +95,7 @@ impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
macro_rules! primitive_deserializer {
($ty:ty, $name:ident, $method:ident $($cast:tt)*) => {
/// A helper deserializer that deserializes a number.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct $name<E> {
value: $ty,
marker: PhantomData<E>
@ -149,7 +149,7 @@ primitive_deserializer!(f64, F64Deserializer, visit_f64);
primitive_deserializer!(char, CharDeserializer, visit_char);
/// A helper deserializer that deserializes a number.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct U32Deserializer<E> {
value: u32,
marker: PhantomData<E>,
@ -212,7 +212,7 @@ impl<'de, E> de::EnumVisitor<'de> for U32Deserializer<E>
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a `&str`.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct StrDeserializer<'a, E> {
value: &'a str,
marker: PhantomData<E>,
@ -276,7 +276,7 @@ impl<'de, 'a, E> de::EnumVisitor<'de> for StrDeserializer<'a, E>
/// A helper deserializer that deserializes a `String`.
#[cfg(any(feature = "std", feature = "collections"))]
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct StringDeserializer<E> {
value: String,
marker: PhantomData<E>,
@ -343,7 +343,7 @@ impl<'de, 'a, E> de::EnumVisitor<'de> for StringDeserializer<E>
/// A helper deserializer that deserializes a `String`.
#[cfg(any(feature = "std", feature = "collections"))]
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct CowStrDeserializer<'a, E> {
value: Cow<'a, str>,
marker: PhantomData<E>,
@ -412,7 +412,7 @@ impl<'de, 'a, E> de::EnumVisitor<'de> for CowStrDeserializer<'a, E>
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a sequence.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct SeqDeserializer<I, E> {
iter: iter::Fuse<I>,
count: usize,
@ -548,7 +548,7 @@ impl<'de, T, E> IntoDeserializer<'de, E> for HashSet<T>
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a sequence using a `SeqVisitor`.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct SeqVisitorDeserializer<V_> {
visitor: V_,
}
@ -764,6 +764,27 @@ impl<'de, I, E> de::SeqVisitor<'de> for MapDeserializer<'de, I, E>
}
}
// Cannot #[derive(Clone)] because of the bound:
//
// <I::Item as private::Pair>::Second: Clone
impl<'de, I, E> Clone for MapDeserializer<'de, I, E>
where I: Iterator + Clone,
I::Item: private::Pair,
<I::Item as private::Pair>::First: IntoDeserializer<'de, E>,
<I::Item as private::Pair>::Second: IntoDeserializer<'de, E> + Clone,
E: de::Error
{
fn clone(&self) -> Self {
MapDeserializer {
iter: self.iter.clone(),
value: self.value.clone(),
count: self.count,
lifetime: self.lifetime,
error: self.error,
}
}
}
// Cannot #[derive(Debug)] because of the bound:
//
// <I::Item as private::Pair>::Second: Debug
@ -912,7 +933,7 @@ impl<'de, K, V, E> IntoDeserializer<'de, E> for HashMap<K, V>
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a map using a `MapVisitor`.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct MapVisitorDeserializer<V_> {
visitor: V_,
}
@ -951,7 +972,7 @@ mod private {
use de::{self, Unexpected};
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct UnitOnly<E> {
marker: PhantomData<E>,
}