Resolves #183 - Serialize and Deserialize for PhantomData
This commit is contained in:
parent
b6965ecde8
commit
4bba342e42
@ -315,6 +315,34 @@ impl<T> Deserialize for Option<T> where T: Deserialize {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A visitor that produces a `PhantomData`.
|
||||
pub struct PhantomDataVisitor<T> {
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<
|
||||
T: Deserialize,
|
||||
> Visitor for PhantomDataVisitor<T> {
|
||||
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,
|
||||
{
|
||||
deserializer.visit_unit(PhantomDataVisitor {marker: PhantomData})
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
macro_rules! seq_impl {
|
||||
(
|
||||
$ty:ty,
|
||||
|
@ -22,6 +22,7 @@ use std::ops;
|
||||
use std::path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
use core::nonzero::{NonZero, Zeroable};
|
||||
@ -119,6 +120,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.visit_unit()
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A `serde::Visitor` for sequence iterators.
|
||||
///
|
||||
/// # Examples
|
||||
|
Loading…
Reference in New Issue
Block a user