Document serde:🇩🇪:impls.

This commit is contained in:
Erick Tryzelaar 2015-09-01 19:13:21 -07:00
parent 55f5f397d7
commit 4b49f716b9

View File

@ -1,4 +1,4 @@
#![allow(missing_docs)] //! This module contains `Deserialize` and `Visitor` implementations.
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::{ use std::collections::{
@ -41,6 +41,7 @@ use de::{
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// A visitor that produces a `()`.
pub struct UnitVisitor; pub struct UnitVisitor;
impl Visitor for UnitVisitor { impl Visitor for UnitVisitor {
@ -69,6 +70,7 @@ impl Deserialize for () {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// A visitor that produces a `bool`.
pub struct BoolVisitor; pub struct BoolVisitor;
impl Visitor for BoolVisitor { impl Visitor for BoolVisitor {
@ -115,11 +117,13 @@ macro_rules! impl_deserialize_num_method {
} }
} }
/// A visitor that produces a primitive type.
pub struct PrimitiveVisitor<T> { pub struct PrimitiveVisitor<T> {
marker: PhantomData<T>, marker: PhantomData<T>,
} }
impl<T> PrimitiveVisitor<T> { impl<T> PrimitiveVisitor<T> {
/// Construct a new `PrimitiveVisitor`.
#[inline] #[inline]
pub fn new() -> Self { pub fn new() -> Self {
PrimitiveVisitor { PrimitiveVisitor {
@ -302,7 +306,7 @@ impl<T> Deserialize for Option<T> where T: Deserialize {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
macro_rules! set_impl { macro_rules! seq_impl {
( (
$ty:ty, $ty:ty,
< $($constraints:ident),* >, < $($constraints:ident),* >,
@ -312,11 +316,13 @@ macro_rules! set_impl {
$with_capacity:expr, $with_capacity:expr,
$insert:expr $insert:expr
) => { ) => {
/// A visitor that produces a sequence.
pub struct $visitor_name<T> { pub struct $visitor_name<T> {
marker: PhantomData<T>, marker: PhantomData<T>,
} }
impl<T> $visitor_name<T> { impl<T> $visitor_name<T> {
/// Construct a new sequence visitor.
pub fn new() -> Self { pub fn new() -> Self {
$visitor_name { $visitor_name {
marker: PhantomData, marker: PhantomData,
@ -364,7 +370,7 @@ macro_rules! set_impl {
} }
} }
set_impl!( seq_impl!(
BinaryHeap<T>, BinaryHeap<T>,
<Deserialize, Ord>, <Deserialize, Ord>,
BinaryHeapVisitor, BinaryHeapVisitor,
@ -373,7 +379,7 @@ set_impl!(
BinaryHeap::with_capacity(visitor.size_hint().0), BinaryHeap::with_capacity(visitor.size_hint().0),
BinaryHeap::push); BinaryHeap::push);
set_impl!( seq_impl!(
BTreeSet<T>, BTreeSet<T>,
<Deserialize, Eq, Ord>, <Deserialize, Eq, Ord>,
BTreeSetVisitor, BTreeSetVisitor,
@ -383,7 +389,7 @@ set_impl!(
BTreeSet::insert); BTreeSet::insert);
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
set_impl!( seq_impl!(
EnumSet<T>, EnumSet<T>,
<Deserialize, CLike>, <Deserialize, CLike>,
EnumSetVisitor, EnumSetVisitor,
@ -392,7 +398,7 @@ set_impl!(
EnumSet::new(), EnumSet::new(),
EnumSet::insert); EnumSet::insert);
set_impl!( seq_impl!(
LinkedList<T>, LinkedList<T>,
<Deserialize>, <Deserialize>,
LinkedListVisitor, LinkedListVisitor,
@ -401,7 +407,7 @@ set_impl!(
LinkedList::new(), LinkedList::new(),
LinkedList::push_back); LinkedList::push_back);
set_impl!( seq_impl!(
HashSet<T>, HashSet<T>,
<Deserialize, Eq, Hash>, <Deserialize, Eq, Hash>,
HashSetVisitor, HashSetVisitor,
@ -410,7 +416,7 @@ set_impl!(
HashSet::with_capacity(visitor.size_hint().0), HashSet::with_capacity(visitor.size_hint().0),
HashSet::insert); HashSet::insert);
set_impl!( seq_impl!(
Vec<T>, Vec<T>,
<Deserialize>, <Deserialize>,
VecVisitor, VecVisitor,
@ -419,7 +425,7 @@ set_impl!(
Vec::with_capacity(visitor.size_hint().0), Vec::with_capacity(visitor.size_hint().0),
Vec::push); Vec::push);
set_impl!( seq_impl!(
VecDeque<T>, VecDeque<T>,
<Deserialize>, <Deserialize>,
VecDequeVisitor, VecDequeVisitor,
@ -435,6 +441,7 @@ struct ArrayVisitor0<T> {
} }
impl<T> ArrayVisitor0<T> { impl<T> ArrayVisitor0<T> {
/// Construct a `ArrayVisitor0<T>`.
pub fn new() -> Self { pub fn new() -> Self {
ArrayVisitor0 { ArrayVisitor0 {
marker: PhantomData, marker: PhantomData,
@ -479,6 +486,7 @@ macro_rules! array_impls {
} }
impl<T> $visitor<T> { impl<T> $visitor<T> {
/// Construct a `ArrayVisitor*<T>`.
pub fn new() -> Self { pub fn new() -> Self {
$visitor { $visitor {
marker: PhantomData marker: PhantomData
@ -568,6 +576,7 @@ macro_rules! tuple_impls {
() => {}; () => {};
($($len:expr => $visitor:ident => ($($name:ident),+),)+) => { ($($len:expr => $visitor:ident => ($($name:ident),+),)+) => {
$( $(
/// Construct a tuple visitor.
pub struct $visitor<$($name,)+> { pub struct $visitor<$($name,)+> {
marker: PhantomData<($($name,)+)>, marker: PhantomData<($($name,)+)>,
} }
@ -575,6 +584,7 @@ macro_rules! tuple_impls {
impl< impl<
$($name: Deserialize,)+ $($name: Deserialize,)+
> $visitor<$($name,)+> { > $visitor<$($name,)+> {
/// Construct a `TupleVisitor*<T>`.
pub fn new() -> Self { pub fn new() -> Self {
$visitor { marker: PhantomData } $visitor { marker: PhantomData }
} }
@ -645,11 +655,13 @@ macro_rules! map_impl {
$with_capacity:expr, $with_capacity:expr,
$insert:expr $insert:expr
) => { ) => {
/// A visitor that produces a map.
pub struct $visitor_name<K, V> { pub struct $visitor_name<K, V> {
marker: PhantomData<$ty>, marker: PhantomData<$ty>,
} }
impl<K, V> $visitor_name<K, V> { impl<K, V> $visitor_name<K, V> {
/// Construct a `MapVisitor*<T>`.
pub fn new() -> Self { pub fn new() -> Self {
$visitor_name { $visitor_name {
marker: PhantomData, marker: PhantomData,