Merge remote-tracking branch 'remotes/origin/v0.6.x'

This commit is contained in:
Erick Tryzelaar 2016-02-24 08:31:17 -08:00
commit 56400ac0ff
2 changed files with 39 additions and 0 deletions

View File

@ -315,6 +315,33 @@ impl<T> Deserialize for Option<T> where T: Deserialize {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// A visitor that produces a `PhantomData`.
pub struct PhantomDataVisitor<T> {
marker: PhantomData<T>,
}
impl<T> Visitor for PhantomDataVisitor<T> where T: Deserialize {
type Value = PhantomData<T>;
#[inline]
fn visit_unit<E>(&mut self) -> Result<PhantomData<T>, E>
where E: Error,
{
Ok(PhantomData)
}
}
impl<T> Deserialize for PhantomData<T> where T: Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<PhantomData<T>, D::Error>
where D: Deserializer,
{
let visitor = PhantomDataVisitor { marker: PhantomData };
deserializer.deserialize_unit_struct("PhantomData", visitor)
}
}
///////////////////////////////////////////////////////////////////////////////
macro_rules! seq_impl { macro_rules! seq_impl {
( (
$ty:ty, $ty:ty,

View File

@ -23,6 +23,7 @@ use std::ops;
use std::path; use std::path;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use std::marker::PhantomData;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use core::nonzero::{NonZero, Zeroable}; use core::nonzero::{NonZero, Zeroable};
@ -121,6 +122,17 @@ impl<T> SeqVisitor for Option<T> where T: Serialize {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
impl<T> Serialize for PhantomData<T> {
#[inline]
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer,
{
serializer.serialize_unit_struct("PhantomData")
}
}
///////////////////////////////////////////////////////////////////////////////
/// A `serde::Visitor` for sequence iterators. /// A `serde::Visitor` for sequence iterators.
/// ///
/// # Examples /// # Examples