Access traits

This commit is contained in:
David Tolnay
2017-04-14 11:58:29 -07:00
parent f2de0509f5
commit 31cec05712
7 changed files with 329 additions and 328 deletions
+13 -13
View File
@@ -8,7 +8,7 @@
use lib::*; use lib::*;
use de::{Deserialize, Deserializer, Visitor, SeqVisitor, MapVisitor, Error}; use de::{Deserialize, Deserializer, Visitor, SeqAccess, MapAccess, Error};
/// An efficient way of discarding data from a deserializer. /// An efficient way of discarding data from a deserializer.
/// ///
@@ -20,7 +20,7 @@ use de::{Deserialize, Deserializer, Visitor, SeqVisitor, MapVisitor, Error};
/// use std::fmt; /// use std::fmt;
/// use std::marker::PhantomData; /// use std::marker::PhantomData;
/// ///
/// use serde::de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqVisitor, IgnoredAny}; /// use serde::de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess, IgnoredAny};
/// ///
/// /// A seed that can be used to deserialize only the `n`th element of a sequence /// /// A seed that can be used to deserialize only the `n`th element of a sequence
/// /// while efficiently discarding elements of any type before or after index `n`. /// /// while efficiently discarding elements of any type before or after index `n`.
@@ -53,19 +53,19 @@ use de::{Deserialize, Deserializer, Visitor, SeqVisitor, MapVisitor, Error};
/// write!(formatter, "a sequence in which we care about element {}", self.n) /// write!(formatter, "a sequence in which we care about element {}", self.n)
/// } /// }
/// ///
/// fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error> /// fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
/// where V: SeqVisitor<'de> /// where A: SeqAccess<'de>
/// { /// {
/// // Skip over the first `n` elements. /// // Skip over the first `n` elements.
/// for i in 0..self.n { /// for i in 0..self.n {
/// // It is an error if the sequence ends before we get to element `n`. /// // It is an error if the sequence ends before we get to element `n`.
/// if seq.visit::<IgnoredAny>()?.is_none() { /// if seq.next_element::<IgnoredAny>()?.is_none() {
/// return Err(de::Error::invalid_length(i, &self)); /// return Err(de::Error::invalid_length(i, &self));
/// } /// }
/// } /// }
/// ///
/// // Deserialize the one we care about. /// // Deserialize the one we care about.
/// let nth = match seq.visit()? { /// let nth = match seq.next_element()? {
/// Some(nth) => nth, /// Some(nth) => nth,
/// None => { /// None => {
/// return Err(de::Error::invalid_length(self.n, &self)); /// return Err(de::Error::invalid_length(self.n, &self));
@@ -73,7 +73,7 @@ use de::{Deserialize, Deserializer, Visitor, SeqVisitor, MapVisitor, Error};
/// }; /// };
/// ///
/// // Skip over any remaining elements in the sequence after `n`. /// // Skip over any remaining elements in the sequence after `n`.
/// while let Some(IgnoredAny) = seq.visit()? { /// while let Some(IgnoredAny) = seq.next_element()? {
/// // ignore /// // ignore
/// } /// }
/// ///
@@ -173,22 +173,22 @@ impl<'de> Visitor<'de> for IgnoredAny {
} }
#[inline] #[inline]
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
while let Some(IgnoredAny) = try!(visitor.visit()) { while let Some(IgnoredAny) = try!(seq.next_element()) {
// Gobble // Gobble
} }
Ok(IgnoredAny) Ok(IgnoredAny)
} }
#[inline] #[inline]
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where where
V: MapVisitor<'de>, A: MapAccess<'de>,
{ {
while let Some((IgnoredAny, IgnoredAny)) = try!(visitor.visit()) { while let Some((IgnoredAny, IgnoredAny)) = try!(map.next_entry()) {
// Gobble // Gobble
} }
Ok(IgnoredAny) Ok(IgnoredAny)
+61 -61
View File
@@ -8,11 +8,11 @@
use lib::*; use lib::*;
use de::{Deserialize, Deserializer, EnumVisitor, Error, SeqVisitor, Unexpected, VariantVisitor, use de::{Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess,
Visitor}; Visitor};
#[cfg(any(feature = "std", feature = "collections"))] #[cfg(any(feature = "std", feature = "collections"))]
use de::MapVisitor; use de::MapAccess;
use de::from_primitive::FromPrimitive; use de::from_primitive::FromPrimitive;
@@ -340,14 +340,14 @@ impl<'de> Visitor<'de> for CStringVisitor {
formatter.write_str("byte array") formatter.write_str("byte array")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<CString, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<CString, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
let len = cmp::min(visitor.size_hint().0, 4096); let len = cmp::min(seq.size_hint().0, 4096);
let mut values = Vec::with_capacity(len); let mut values = Vec::with_capacity(len);
while let Some(value) = try!(visitor.visit()) { while let Some(value) = try!(seq.next_element()) {
values.push(value); values.push(value);
} }
@@ -495,7 +495,7 @@ macro_rules! seq_impl {
( (
$ty:ident < T $(, $typaram:ident)* >, $ty:ident < T $(, $typaram:ident)* >,
$visitor_ty:ident $( < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* > )*, $visitor_ty:ident $( < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* > )*,
$visitor:ident, $access:ident,
$ctor:expr, $ctor:expr,
$with_capacity:expr, $with_capacity:expr,
$insert:expr $insert:expr
@@ -524,13 +524,13 @@ macro_rules! seq_impl {
} }
#[inline] #[inline]
fn visit_seq<V>(self, mut $visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut $access: A) -> Result<Self::Value, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
let mut values = $with_capacity; let mut values = $with_capacity;
while let Some(value) = try!($visitor.visit()) { while let Some(value) = try!($access.next_element()) {
$insert(&mut values, value); $insert(&mut values, value);
} }
@@ -628,9 +628,9 @@ impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]> {
} }
#[inline] #[inline]
fn visit_seq<V>(self, _: V) -> Result<[T; 0], V::Error> fn visit_seq<A>(self, _: A) -> Result<[T; 0], A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
Ok([]) Ok([])
} }
@@ -660,12 +660,12 @@ macro_rules! array_impls {
} }
#[inline] #[inline]
fn visit_seq<V>(self, mut visitor: V) -> Result<[T; $len], V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<[T; $len], A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
$( $(
let $name = match try!(visitor.visit()) { let $name = match try!(seq.next_element()) {
Some(val) => val, Some(val) => val,
None => return Err(Error::invalid_length($n, &self)), None => return Err(Error::invalid_length($n, &self)),
}; };
@@ -749,12 +749,12 @@ macro_rules! tuple_impls {
#[inline] #[inline]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn visit_seq<V>(self, mut visitor: V) -> Result<($($name,)+), V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<($($name,)+), A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
$( $(
let $name = match try!(visitor.visit()) { let $name = match try!(seq.next_element()) {
Some(value) => value, Some(value) => value,
None => return Err(Error::invalid_length($n, &self)), None => return Err(Error::invalid_length($n, &self)),
}; };
@@ -802,7 +802,7 @@ macro_rules! map_impl {
( (
$ty:ident < K, V $(, $typaram:ident)* >, $ty:ident < K, V $(, $typaram:ident)* >,
$visitor_ty:ident < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* >, $visitor_ty:ident < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* >,
$visitor:ident, $access:ident,
$ctor:expr, $ctor:expr,
$with_capacity:expr $with_capacity:expr
) => { ) => {
@@ -831,13 +831,13 @@ macro_rules! map_impl {
} }
#[inline] #[inline]
fn visit_map<Visitor>(self, mut $visitor: Visitor) -> Result<Self::Value, Visitor::Error> fn visit_map<A>(self, mut $access: A) -> Result<Self::Value, A::Error>
where where
Visitor: MapVisitor<'de>, A: MapAccess<'de>,
{ {
let mut values = $with_capacity; let mut values = $with_capacity;
while let Some((key, value)) = try!($visitor.visit()) { while let Some((key, value)) = try!($access.next_entry()) {
values.insert(key, value); values.insert(key, value);
} }
@@ -1086,29 +1086,29 @@ impl<'de> Visitor<'de> for OsStringVisitor {
} }
#[cfg(unix)] #[cfg(unix)]
fn visit_enum<V>(self, visitor: V) -> Result<OsString, V::Error> fn visit_enum<A>(self, data: A) -> Result<OsString, A::Error>
where where
V: EnumVisitor<'de>, A: EnumAccess<'de>,
{ {
use std::os::unix::ffi::OsStringExt; use std::os::unix::ffi::OsStringExt;
match try!(visitor.visit_variant()) { match try!(data.variant()) {
(OsStringKind::Unix, variant) => variant.visit_newtype().map(OsString::from_vec), (OsStringKind::Unix, variant) => variant.deserialize_newtype().map(OsString::from_vec),
(OsStringKind::Windows, _) => Err(Error::custom("cannot deserialize Windows OS string on Unix",),), (OsStringKind::Windows, _) => Err(Error::custom("cannot deserialize Windows OS string on Unix",),),
} }
} }
#[cfg(windows)] #[cfg(windows)]
fn visit_enum<V>(self, visitor: V) -> Result<OsString, V::Error> fn visit_enum<A>(self, data: A) -> Result<OsString, A::Error>
where where
V: EnumVisitor<'de>, A: EnumAccess<'de>,
{ {
use std::os::windows::ffi::OsStringExt; use std::os::windows::ffi::OsStringExt;
match try!(visitor.visit_variant()) { match try!(data.variant()) {
(OsStringKind::Windows, variant) => { (OsStringKind::Windows, variant) => {
variant variant
.visit_newtype::<Vec<u16>>() .deserialize_newtype::<Vec<u16>>()
.map(|vec| OsString::from_wide(&vec)) .map(|vec| OsString::from_wide(&vec))
} }
(OsStringKind::Unix, _) => Err(Error::custom("cannot deserialize Unix OS string on Windows",),), (OsStringKind::Unix, _) => Err(Error::custom("cannot deserialize Unix OS string on Windows",),),
@@ -1285,17 +1285,17 @@ impl<'de> Deserialize<'de> for Duration {
formatter.write_str("struct Duration") formatter.write_str("struct Duration")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<Duration, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Duration, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
let secs: u64 = match try!(visitor.visit()) { let secs: u64 = match try!(seq.next_element()) {
Some(value) => value, Some(value) => value,
None => { None => {
return Err(Error::invalid_length(0, &self)); return Err(Error::invalid_length(0, &self));
} }
}; };
let nanos: u32 = match try!(visitor.visit()) { let nanos: u32 = match try!(seq.next_element()) {
Some(value) => value, Some(value) => value,
None => { None => {
return Err(Error::invalid_length(1, &self)); return Err(Error::invalid_length(1, &self));
@@ -1304,35 +1304,35 @@ impl<'de> Deserialize<'de> for Duration {
Ok(Duration::new(secs, nanos)) Ok(Duration::new(secs, nanos))
} }
fn visit_map<V>(self, mut visitor: V) -> Result<Duration, V::Error> fn visit_map<A>(self, mut map: A) -> Result<Duration, A::Error>
where where
V: MapVisitor<'de>, A: MapAccess<'de>,
{ {
let mut secs: Option<u64> = None; let mut secs: Option<u64> = None;
let mut nanos: Option<u32> = None; let mut nanos: Option<u32> = None;
while let Some(key) = try!(visitor.visit_key::<Field>()) { while let Some(key) = try!(map.next_key()) {
match key { match key {
Field::Secs => { Field::Secs => {
if secs.is_some() { if secs.is_some() {
return Err(<V::Error as Error>::duplicate_field("secs")); return Err(<A::Error as Error>::duplicate_field("secs"));
} }
secs = Some(try!(visitor.visit_value())); secs = Some(try!(map.next_value()));
} }
Field::Nanos => { Field::Nanos => {
if nanos.is_some() { if nanos.is_some() {
return Err(<V::Error as Error>::duplicate_field("nanos")); return Err(<A::Error as Error>::duplicate_field("nanos"));
} }
nanos = Some(try!(visitor.visit_value())); nanos = Some(try!(map.next_value()));
} }
} }
} }
let secs = match secs { let secs = match secs {
Some(secs) => secs, Some(secs) => secs,
None => return Err(<V::Error as Error>::missing_field("secs")), None => return Err(<A::Error as Error>::missing_field("secs")),
}; };
let nanos = match nanos { let nanos = match nanos {
Some(nanos) => nanos, Some(nanos) => nanos,
None => return Err(<V::Error as Error>::missing_field("nanos")), None => return Err(<A::Error as Error>::missing_field("nanos")),
}; };
Ok(Duration::new(secs, nanos)) Ok(Duration::new(secs, nanos))
} }
@@ -1425,17 +1425,17 @@ where
formatter.write_str("struct Range") formatter.write_str("struct Range")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<ops::Range<Idx>, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<ops::Range<Idx>, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
let start: Idx = match try!(visitor.visit()) { let start: Idx = match try!(seq.next_element()) {
Some(value) => value, Some(value) => value,
None => { None => {
return Err(Error::invalid_length(0, &self)); return Err(Error::invalid_length(0, &self));
} }
}; };
let end: Idx = match try!(visitor.visit()) { let end: Idx = match try!(seq.next_element()) {
Some(value) => value, Some(value) => value,
None => { None => {
return Err(Error::invalid_length(1, &self)); return Err(Error::invalid_length(1, &self));
@@ -1444,35 +1444,35 @@ where
Ok(start..end) Ok(start..end)
} }
fn visit_map<V>(self, mut visitor: V) -> Result<ops::Range<Idx>, V::Error> fn visit_map<A>(self, mut map: A) -> Result<ops::Range<Idx>, A::Error>
where where
V: MapVisitor<'de>, A: MapAccess<'de>,
{ {
let mut start: Option<Idx> = None; let mut start: Option<Idx> = None;
let mut end: Option<Idx> = None; let mut end: Option<Idx> = None;
while let Some(key) = try!(visitor.visit_key::<Field>()) { while let Some(key) = try!(map.next_key()) {
match key { match key {
Field::Start => { Field::Start => {
if start.is_some() { if start.is_some() {
return Err(<V::Error as Error>::duplicate_field("start")); return Err(<A::Error as Error>::duplicate_field("start"));
} }
start = Some(try!(visitor.visit_value())); start = Some(try!(map.next_value()));
} }
Field::End => { Field::End => {
if end.is_some() { if end.is_some() {
return Err(<V::Error as Error>::duplicate_field("end")); return Err(<A::Error as Error>::duplicate_field("end"));
} }
end = Some(try!(visitor.visit_value())); end = Some(try!(map.next_value()));
} }
} }
} }
let start = match start { let start = match start {
Some(start) => start, Some(start) => start,
None => return Err(<V::Error as Error>::missing_field("start")), None => return Err(<A::Error as Error>::missing_field("start")),
}; };
let end = match end { let end = match end {
Some(end) => end, Some(end) => end,
None => return Err(<V::Error as Error>::missing_field("end")), None => return Err(<A::Error as Error>::missing_field("end")),
}; };
Ok(start..end) Ok(start..end)
} }
@@ -1598,13 +1598,13 @@ where
formatter.write_str("enum Result") formatter.write_str("enum Result")
} }
fn visit_enum<V>(self, visitor: V) -> Result<Result<T, E>, V::Error> fn visit_enum<A>(self, data: A) -> Result<Result<T, E>, A::Error>
where where
V: EnumVisitor<'de>, A: EnumAccess<'de>,
{ {
match try!(visitor.visit_variant()) { match try!(data.variant()) {
(Field::Ok, variant) => variant.visit_newtype().map(Ok), (Field::Ok, variant) => variant.deserialize_newtype().map(Ok),
(Field::Err, variant) => variant.visit_newtype().map(Err), (Field::Err, variant) => variant.deserialize_newtype().map(Err),
} }
} }
} }
+118 -117
View File
@@ -585,7 +585,7 @@ where
/// use std::fmt; /// use std::fmt;
/// use std::marker::PhantomData; /// use std::marker::PhantomData;
/// ///
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, Visitor, SeqVisitor}; /// use serde::de::{Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess};
/// ///
/// // A DeserializeSeed implementation that uses stateful deserialization to /// // A DeserializeSeed implementation that uses stateful deserialization to
/// // append array elements onto the end of an existing vector. The preexisting /// // append array elements onto the end of an existing vector. The preexisting
@@ -618,12 +618,12 @@ where
/// write!(formatter, "an array of integers") /// write!(formatter, "an array of integers")
/// } /// }
/// ///
/// fn visit_seq<V>(self, mut visitor: V) -> Result<(), V::Error> /// fn visit_seq<A>(self, mut seq: A) -> Result<(), A::Error>
/// where V: SeqVisitor<'de> /// where A: SeqAccess<'de>
/// { /// {
/// // Visit each element in the inner array and push it onto /// // Visit each element in the inner array and push it onto
/// // the existing vector. /// // the existing vector.
/// while let Some(elem) = visitor.visit()? { /// while let Some(elem) = seq.next_element()? {
/// self.0.push(elem); /// self.0.push(elem);
/// } /// }
/// Ok(()) /// Ok(())
@@ -648,14 +648,14 @@ where
/// write!(formatter, "an array of arrays") /// write!(formatter, "an array of arrays")
/// } /// }
/// ///
/// fn visit_seq<V>(self, mut visitor: V) -> Result<Vec<T>, V::Error> /// fn visit_seq<A>(self, mut seq: A) -> Result<Vec<T>, A::Error>
/// where V: SeqVisitor<'de> /// where A: SeqAccess<'de>
/// { /// {
/// // Create a single Vec to hold the flattened contents. /// // Create a single Vec to hold the flattened contents.
/// let mut vec = Vec::new(); /// let mut vec = Vec::new();
/// ///
/// // Each iteration through this loop is one inner array. /// // Each iteration through this loop is one inner array.
/// while let Some(()) = visitor.visit_seed(ExtendVec(&mut vec))? { /// while let Some(()) = seq.next_element_seed(ExtendVec(&mut vec))? {
/// // Nothing to do; inner array has been appended into `vec`. /// // Nothing to do; inner array has been appended into `vec`.
/// } /// }
/// ///
@@ -1260,29 +1260,29 @@ pub trait Visitor<'de>: Sized {
} }
/// Deserialize `Value` as a sequence of elements. /// Deserialize `Value` as a sequence of elements.
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, seq: A) -> Result<Self::Value, A::Error>
where where
V: SeqVisitor<'de>, A: SeqAccess<'de>,
{ {
let _ = visitor; let _ = seq;
Err(Error::invalid_type(Unexpected::Seq, &self)) Err(Error::invalid_type(Unexpected::Seq, &self))
} }
/// Deserialize `Value` as a key-value map. /// Deserialize `Value` as a key-value map.
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
where where
V: MapVisitor<'de>, A: MapAccess<'de>,
{ {
let _ = visitor; let _ = map;
Err(Error::invalid_type(Unexpected::Map, &self)) Err(Error::invalid_type(Unexpected::Map, &self))
} }
/// Deserialize `Value` as an enum. /// Deserialize `Value` as an enum.
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
where where
V: EnumVisitor<'de>, A: EnumAccess<'de>,
{ {
let _ = visitor; let _ = data;
Err(Error::invalid_type(Unexpected::Enum, &self)) Err(Error::invalid_type(Unexpected::Enum, &self))
} }
@@ -1345,11 +1345,11 @@ pub trait Visitor<'de>: Sized {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// `SeqVisitor` visits each item in a sequence. /// Provides a `Visitor` access to each element of a sequence in the input.
/// ///
/// This is a trait that a `Deserializer` passes to a `Visitor` implementation, /// This is a trait that a `Deserializer` passes to a `Visitor` implementation,
/// which deserializes each item in a sequence. /// which deserializes each item in a sequence.
pub trait SeqVisitor<'de> { pub trait SeqAccess<'de> {
/// The error type that can be returned if some error occurs during /// The error type that can be returned if some error occurs during
/// deserialization. /// deserialization.
type Error: Error; type Error: Error;
@@ -1357,9 +1357,9 @@ pub trait SeqVisitor<'de> {
/// This returns `Ok(Some(value))` for the next value in the sequence, or /// This returns `Ok(Some(value))` for the next value in the sequence, or
/// `Ok(None)` if there are no more remaining items. /// `Ok(None)` if there are no more remaining items.
/// ///
/// `Deserialize` implementations should typically use `SeqVisitor::visit` /// `Deserialize` implementations should typically use
/// instead. /// `SeqAcccess::next_element` instead.
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: DeserializeSeed<'de>; T: DeserializeSeed<'de>;
@@ -1367,13 +1367,13 @@ pub trait SeqVisitor<'de> {
/// `Ok(None)` if there are no more remaining items. /// `Ok(None)` if there are no more remaining items.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `SeqVisitor` implementations should not override the default behavior. /// `SeqAccess` implementations should not override the default behavior.
#[inline] #[inline]
fn visit<T>(&mut self) -> Result<Option<T>, Self::Error> fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error>
where where
T: Deserialize<'de>, T: Deserialize<'de>,
{ {
self.visit_seed(PhantomData) self.next_element_seed(PhantomData)
} }
/// Return the lower and upper bound of items remaining in the sequence. /// Return the lower and upper bound of items remaining in the sequence.
@@ -1383,26 +1383,26 @@ pub trait SeqVisitor<'de> {
} }
} }
impl<'de, 'a, V> SeqVisitor<'de> for &'a mut V impl<'de, 'a, V> SeqAccess<'de> for &'a mut V
where where
V: SeqVisitor<'de>, V: SeqAccess<'de>,
{ {
type Error = V::Error; type Error = V::Error;
#[inline] #[inline]
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, V::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, V::Error>
where where
T: DeserializeSeed<'de>, T: DeserializeSeed<'de>,
{ {
(**self).visit_seed(seed) (**self).next_element_seed(seed)
} }
#[inline] #[inline]
fn visit<T>(&mut self) -> Result<Option<T>, V::Error> fn next_element<T>(&mut self) -> Result<Option<T>, V::Error>
where where
T: Deserialize<'de>, T: Deserialize<'de>,
{ {
(**self).visit() (**self).next_element()
} }
#[inline] #[inline]
@@ -1413,10 +1413,10 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// `MapVisitor` visits each item in a sequence. /// Provides a `Visitor` access to each entry of a map in the input.
/// ///
/// This is a trait that a `Deserializer` passes to a `Visitor` implementation. /// This is a trait that a `Deserializer` passes to a `Visitor` implementation.
pub trait MapVisitor<'de> { pub trait MapAccess<'de> {
/// The error type that can be returned if some error occurs during /// The error type that can be returned if some error occurs during
/// deserialization. /// deserialization.
type Error: Error; type Error: Error;
@@ -1425,29 +1425,29 @@ pub trait MapVisitor<'de> {
/// if there are no more remaining entries. /// if there are no more remaining entries.
/// ///
/// `Deserialize` implementations should typically use /// `Deserialize` implementations should typically use
/// `MapVisitor::visit_key` or `MapVisitor::visit` instead. /// `MapAccess::next_key` or `MapAccess::next_entry` instead.
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error> fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
where where
K: DeserializeSeed<'de>; K: DeserializeSeed<'de>;
/// This returns a `Ok(value)` for the next value in the map. /// This returns a `Ok(value)` for the next value in the map.
/// ///
/// `Deserialize` implementations should typically use /// `Deserialize` implementations should typically use
/// `MapVisitor::visit_value` instead. /// `MapAccess::next_value` instead.
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error> fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
where where
V: DeserializeSeed<'de>; V: DeserializeSeed<'de>;
/// This returns `Ok(Some((key, value)))` for the next (key-value) pair in /// This returns `Ok(Some((key, value)))` for the next (key-value) pair in
/// the map, or `Ok(None)` if there are no more remaining items. /// the map, or `Ok(None)` if there are no more remaining items.
/// ///
/// `MapVisitor` implementations should override the default behavior if a /// `MapAccess` implementations should override the default behavior if a
/// more efficient implementation is possible. /// more efficient implementation is possible.
/// ///
/// `Deserialize` implementations should typically use `MapVisitor::visit` /// `Deserialize` implementations should typically use
/// instead. /// `MapAccess::next_entry` instead.
#[inline] #[inline]
fn visit_seed<K, V>( fn next_entry_seed<K, V>(
&mut self, &mut self,
kseed: K, kseed: K,
vseed: V, vseed: V,
@@ -1456,9 +1456,9 @@ pub trait MapVisitor<'de> {
K: DeserializeSeed<'de>, K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {
match try!(self.visit_key_seed(kseed)) { match try!(self.next_key_seed(kseed)) {
Some(key) => { Some(key) => {
let value = try!(self.visit_value_seed(vseed)); let value = try!(self.next_value_seed(vseed));
Ok(Some((key, value))) Ok(Some((key, value)))
} }
None => Ok(None), None => Ok(None),
@@ -1469,39 +1469,39 @@ pub trait MapVisitor<'de> {
/// if there are no more remaining entries. /// if there are no more remaining entries.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `MapVisitor` implementations should not override the default behavior. /// `MapAccess` implementations should not override the default behavior.
#[inline] #[inline]
fn visit_key<K>(&mut self) -> Result<Option<K>, Self::Error> fn next_key<K>(&mut self) -> Result<Option<K>, Self::Error>
where where
K: Deserialize<'de>, K: Deserialize<'de>,
{ {
self.visit_key_seed(PhantomData) self.next_key_seed(PhantomData)
} }
/// This returns a `Ok(value)` for the next value in the map. /// This returns a `Ok(value)` for the next value in the map.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `MapVisitor` implementations should not override the default behavior. /// `MapAccess` implementations should not override the default behavior.
#[inline] #[inline]
fn visit_value<V>(&mut self) -> Result<V, Self::Error> fn next_value<V>(&mut self) -> Result<V, Self::Error>
where where
V: Deserialize<'de>, V: Deserialize<'de>,
{ {
self.visit_value_seed(PhantomData) self.next_value_seed(PhantomData)
} }
/// This returns `Ok(Some((key, value)))` for the next (key-value) pair in /// This returns `Ok(Some((key, value)))` for the next (key-value) pair in
/// the map, or `Ok(None)` if there are no more remaining items. /// the map, or `Ok(None)` if there are no more remaining items.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `MapVisitor` implementations should not override the default behavior. /// `MapAccess` implementations should not override the default behavior.
#[inline] #[inline]
fn visit<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error> fn next_entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
where where
K: Deserialize<'de>, K: Deserialize<'de>,
V: Deserialize<'de>, V: Deserialize<'de>,
{ {
self.visit_seed(PhantomData, PhantomData) self.next_entry_seed(PhantomData, PhantomData)
} }
/// Return the lower and upper bound of items remaining in the sequence. /// Return the lower and upper bound of items remaining in the sequence.
@@ -1511,30 +1511,30 @@ pub trait MapVisitor<'de> {
} }
} }
impl<'de, 'a, V_> MapVisitor<'de> for &'a mut V_ impl<'de, 'a, V_> MapAccess<'de> for &'a mut V_
where where
V_: MapVisitor<'de>, V_: MapAccess<'de>,
{ {
type Error = V_::Error; type Error = V_::Error;
#[inline] #[inline]
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error> fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
where where
K: DeserializeSeed<'de>, K: DeserializeSeed<'de>,
{ {
(**self).visit_key_seed(seed) (**self).next_key_seed(seed)
} }
#[inline] #[inline]
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error> fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
where where
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {
(**self).visit_value_seed(seed) (**self).next_value_seed(seed)
} }
#[inline] #[inline]
fn visit_seed<K, V>( fn next_entry_seed<K, V>(
&mut self, &mut self,
kseed: K, kseed: K,
vseed: V, vseed: V,
@@ -1543,32 +1543,32 @@ where
K: DeserializeSeed<'de>, K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {
(**self).visit_seed(kseed, vseed) (**self).next_entry_seed(kseed, vseed)
} }
#[inline] #[inline]
fn visit<K, V>(&mut self) -> Result<Option<(K, V)>, V_::Error> fn next_entry<K, V>(&mut self) -> Result<Option<(K, V)>, V_::Error>
where where
K: Deserialize<'de>, K: Deserialize<'de>,
V: Deserialize<'de>, V: Deserialize<'de>,
{ {
(**self).visit() (**self).next_entry()
} }
#[inline] #[inline]
fn visit_key<K>(&mut self) -> Result<Option<K>, V_::Error> fn next_key<K>(&mut self) -> Result<Option<K>, V_::Error>
where where
K: Deserialize<'de>, K: Deserialize<'de>,
{ {
(**self).visit_key() (**self).next_key()
} }
#[inline] #[inline]
fn visit_value<V>(&mut self) -> Result<V, V_::Error> fn next_value<V>(&mut self) -> Result<V, V_::Error>
where where
V: Deserialize<'de>, V: Deserialize<'de>,
{ {
(**self).visit_value() (**self).next_value()
} }
#[inline] #[inline]
@@ -1579,44 +1579,45 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// `EnumVisitor` is a visitor that is created by the `Deserializer` and passed /// Provides a `Visitor` access to the data of an enum in the input.
/// to the `Deserialize` in order to identify which variant of an enum to ///
/// deserialize. /// `EnumAccess` is created by the `Deserializer` and passed to the
pub trait EnumVisitor<'de>: Sized { /// `Visitor` in order to identify which variant of an enum to deserialize.
pub trait EnumAccess<'de>: Sized {
/// The error type that can be returned if some error occurs during /// The error type that can be returned if some error occurs during
/// deserialization. /// deserialization.
type Error: Error; type Error: Error;
/// The `Visitor` that will be used to deserialize the content of the enum /// The `Visitor` that will be used to deserialize the content of the enum
/// variant. /// variant.
type Variant: VariantVisitor<'de, Error = Self::Error>; type Variant: VariantAccess<'de, Error = Self::Error>;
/// `visit_variant` is called to identify which variant to deserialize. /// `variant` is called to identify which variant to deserialize.
/// ///
/// `Deserialize` implementations should typically use /// `Deserialize` implementations should typically use `EnumAccess::variant`
/// `EnumVisitor::visit_variant` instead. /// instead.
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error> fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
where where
V: DeserializeSeed<'de>; V: DeserializeSeed<'de>;
/// `visit_variant` is called to identify which variant to deserialize. /// `variant` is called to identify which variant to deserialize.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `EnumVisitor` implementations should not override the default behavior. /// `EnumAccess` implementations should not override the default behavior.
#[inline] #[inline]
fn visit_variant<V>(self) -> Result<(V, Self::Variant), Self::Error> fn variant<V>(self) -> Result<(V, Self::Variant), Self::Error>
where where
V: Deserialize<'de>, V: Deserialize<'de>,
{ {
self.visit_variant_seed(PhantomData) self.variant_seed(PhantomData)
} }
} }
/// `VariantVisitor` is a visitor that is created by the `Deserializer` and /// `VariantAccess` is a visitor that is created by the `Deserializer` and
/// passed to the `Deserialize` to deserialize the content of a particular enum /// passed to the `Deserialize` to deserialize the content of a particular enum
/// variant. /// variant.
pub trait VariantVisitor<'de>: Sized { pub trait VariantAccess<'de>: Sized {
/// The error type that can be returned if some error occurs during /// The error type that can be returned if some error occurs during
/// deserialization. Must match the error type of our `EnumVisitor`. /// deserialization. Must match the error type of our `EnumAccess`.
type Error: Error; type Error: Error;
/// Called when deserializing a variant with no values. /// Called when deserializing a variant with no values.
@@ -1625,55 +1626,55 @@ pub trait VariantVisitor<'de>: Sized {
/// `invalid_type` error should be constructed: /// `invalid_type` error should be constructed:
/// ///
/// ```rust /// ```rust
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantVisitor, Unexpected}; /// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// # /// #
/// # struct X; /// # struct X;
/// # /// #
/// # impl<'de> VariantVisitor<'de> for X { /// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error; /// # type Error = value::Error;
/// # /// #
/// fn visit_unit(self) -> Result<(), Self::Error> { /// fn deserialize_unit(self) -> Result<(), Self::Error> {
/// // What the data actually contained; suppose it is a tuple variant. /// // What the data actually contained; suppose it is a tuple variant.
/// let unexp = Unexpected::TupleVariant; /// let unexp = Unexpected::TupleVariant;
/// Err(de::Error::invalid_type(unexp, &"unit variant")) /// Err(de::Error::invalid_type(unexp, &"unit variant"))
/// } /// }
/// # /// #
/// # fn visit_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error> /// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de> /// # where T: DeserializeSeed<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// # fn visit_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// # fn visit_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # } /// # }
/// ``` /// ```
fn visit_unit(self) -> Result<(), Self::Error>; fn deserialize_unit(self) -> Result<(), Self::Error>;
/// Called when deserializing a variant with a single value. /// Called when deserializing a variant with a single value.
/// ///
/// `Deserialize` implementations should typically use /// `Deserialize` implementations should typically use
/// `VariantVisitor::visit_newtype` instead. /// `VariantAccess::deserialize_newtype` instead.
/// ///
/// If the data contains a different type of variant, the following /// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed: /// `invalid_type` error should be constructed:
/// ///
/// ```rust /// ```rust
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantVisitor, Unexpected}; /// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// # /// #
/// # struct X; /// # struct X;
/// # /// #
/// # impl<'de> VariantVisitor<'de> for X { /// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error; /// # type Error = value::Error;
/// # /// #
/// # fn visit_unit(self) -> Result<(), Self::Error> { /// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # unimplemented!() /// # unimplemented!()
/// # } /// # }
/// # /// #
/// fn visit_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error> /// fn deserialize_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
/// where T: DeserializeSeed<'de> /// where T: DeserializeSeed<'de>
/// { /// {
/// // What the data actually contained; suppose it is a unit variant. /// // What the data actually contained; suppose it is a unit variant.
@@ -1681,30 +1682,30 @@ pub trait VariantVisitor<'de>: Sized {
/// Err(de::Error::invalid_type(unexp, &"newtype variant")) /// Err(de::Error::invalid_type(unexp, &"newtype variant"))
/// } /// }
/// # /// #
/// # fn visit_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// # fn visit_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # } /// # }
/// ``` /// ```
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
where where
T: DeserializeSeed<'de>; T: DeserializeSeed<'de>;
/// Called when deserializing a variant with a single value. /// Called when deserializing a variant with a single value.
/// ///
/// This method exists as a convenience for `Deserialize` implementations. /// This method exists as a convenience for `Deserialize` implementations.
/// `VariantVisitor` implementations should not override the default /// `VariantAccess` implementations should not override the default
/// behavior. /// behavior.
#[inline] #[inline]
fn visit_newtype<T>(self) -> Result<T, Self::Error> fn deserialize_newtype<T>(self) -> Result<T, Self::Error>
where where
T: Deserialize<'de>, T: Deserialize<'de>,
{ {
self.visit_newtype_seed(PhantomData) self.deserialize_newtype_seed(PhantomData)
} }
/// Called when deserializing a tuple-like variant. /// Called when deserializing a tuple-like variant.
@@ -1715,24 +1716,24 @@ pub trait VariantVisitor<'de>: Sized {
/// `invalid_type` error should be constructed: /// `invalid_type` error should be constructed:
/// ///
/// ```rust /// ```rust
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantVisitor, Unexpected}; /// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// # /// #
/// # struct X; /// # struct X;
/// # /// #
/// # impl<'de> VariantVisitor<'de> for X { /// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error; /// # type Error = value::Error;
/// # /// #
/// # fn visit_unit(self) -> Result<(), Self::Error> { /// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # unimplemented!() /// # unimplemented!()
/// # } /// # }
/// # /// #
/// # fn visit_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error> /// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de> /// # where T: DeserializeSeed<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// fn visit_tuple<V>(self, /// fn deserialize_tuple<V>(self,
/// _len: usize, /// _len: usize,
/// _visitor: V) -> Result<V::Value, Self::Error> /// _visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de> /// where V: Visitor<'de>
/// { /// {
/// // What the data actually contained; suppose it is a unit variant. /// // What the data actually contained; suppose it is a unit variant.
@@ -1740,12 +1741,12 @@ pub trait VariantVisitor<'de>: Sized {
/// Err(de::Error::invalid_type(unexp, &"tuple variant")) /// Err(de::Error::invalid_type(unexp, &"tuple variant"))
/// } /// }
/// # /// #
/// # fn visit_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_struct<V>(self, _: &[&str], _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # } /// # }
/// ``` /// ```
fn visit_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error> fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
where where
V: Visitor<'de>; V: Visitor<'de>;
@@ -1757,28 +1758,28 @@ pub trait VariantVisitor<'de>: Sized {
/// `invalid_type` error should be constructed: /// `invalid_type` error should be constructed:
/// ///
/// ```rust /// ```rust
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantVisitor, Unexpected}; /// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// # /// #
/// # struct X; /// # struct X;
/// # /// #
/// # impl<'de> VariantVisitor<'de> for X { /// # impl<'de> VariantAccess<'de> for X {
/// # type Error = value::Error; /// # type Error = value::Error;
/// # /// #
/// # fn visit_unit(self) -> Result<(), Self::Error> { /// # fn deserialize_unit(self) -> Result<(), Self::Error> {
/// # unimplemented!() /// # unimplemented!()
/// # } /// # }
/// # /// #
/// # fn visit_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error> /// # fn deserialize_newtype_seed<T>(self, _: T) -> Result<T::Value, Self::Error>
/// # where T: DeserializeSeed<'de> /// # where T: DeserializeSeed<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// # fn visit_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error> /// # fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de> /// # where V: Visitor<'de>
/// # { unimplemented!() } /// # { unimplemented!() }
/// # /// #
/// fn visit_struct<V>(self, /// fn deserialize_struct<V>(self,
/// _fields: &'static [&'static str], /// _fields: &'static [&'static str],
/// _visitor: V) -> Result<V::Value, Self::Error> /// _visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de> /// where V: Visitor<'de>
/// { /// {
/// // What the data actually contained; suppose it is a unit variant. /// // What the data actually contained; suppose it is a unit variant.
@@ -1787,7 +1788,7 @@ pub trait VariantVisitor<'de>: Sized {
/// } /// }
/// # } /// # }
/// ``` /// ```
fn visit_struct<V>( fn deserialize_struct<V>(
self, self,
fields: &'static [&'static str], fields: &'static [&'static str],
visitor: V, visitor: V,
+30 -30
View File
@@ -10,7 +10,7 @@
use lib::*; use lib::*;
use de::{self, IntoDeserializer, Expected, SeqVisitor}; use de::{self, IntoDeserializer, Expected, SeqAccess};
use self::private::{First, Second}; use self::private::{First, Second};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -223,14 +223,14 @@ where
} }
} }
impl<'de, E> de::EnumVisitor<'de> for U32Deserializer<E> impl<'de, E> de::EnumAccess<'de> for U32Deserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = private::UnitOnly<E>; type Variant = private::UnitOnly<E>;
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error> fn variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -293,14 +293,14 @@ where
} }
} }
impl<'de, 'a, E> de::EnumVisitor<'de> for StrDeserializer<'a, E> impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = private::UnitOnly<E>; type Variant = private::UnitOnly<E>;
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error> fn variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -367,14 +367,14 @@ where
} }
#[cfg(any(feature = "std", feature = "collections"))] #[cfg(any(feature = "std", feature = "collections"))]
impl<'de, 'a, E> de::EnumVisitor<'de> for StringDeserializer<E> impl<'de, 'a, E> de::EnumAccess<'de> for StringDeserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = private::UnitOnly<E>; type Variant = private::UnitOnly<E>;
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error> fn variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -444,14 +444,14 @@ where
} }
#[cfg(any(feature = "std", feature = "collections"))] #[cfg(any(feature = "std", feature = "collections"))]
impl<'de, 'a, E> de::EnumVisitor<'de> for CowStrDeserializer<'a, E> impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = private::UnitOnly<E>; type Variant = private::UnitOnly<E>;
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error> fn variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -524,7 +524,7 @@ where
} }
} }
impl<'de, I, T, E> de::SeqVisitor<'de> for SeqDeserializer<I, E> impl<'de, I, T, E> de::SeqAccess<'de> for SeqDeserializer<I, E>
where where
I: Iterator<Item = T>, I: Iterator<Item = T>,
T: IntoDeserializer<'de, E>, T: IntoDeserializer<'de, E>,
@@ -532,7 +532,7 @@ where
{ {
type Error = E; type Error = E;
fn visit_seed<V>(&mut self, seed: V) -> Result<Option<V::Value>, Self::Error> fn next_element_seed<V>(&mut self, seed: V) -> Result<Option<V::Value>, Self::Error>
where where
V: de::DeserializeSeed<'de>, V: de::DeserializeSeed<'de>,
{ {
@@ -605,7 +605,7 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a sequence using a `SeqVisitor`. /// A helper deserializer that deserializes a sequence using a `SeqAccess`.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SeqVisitorDeserializer<V_> { pub struct SeqVisitorDeserializer<V_> {
visitor: V_, visitor: V_,
@@ -620,7 +620,7 @@ impl<V_> SeqVisitorDeserializer<V_> {
impl<'de, V_> de::Deserializer<'de> for SeqVisitorDeserializer<V_> impl<'de, V_> de::Deserializer<'de> for SeqVisitorDeserializer<V_>
where where
V_: de::SeqVisitor<'de>, V_: de::SeqAccess<'de>,
{ {
type Error = V_::Error; type Error = V_::Error;
@@ -747,7 +747,7 @@ where
} }
} }
impl<'de, I, E> de::MapVisitor<'de> for MapDeserializer<'de, I, E> impl<'de, I, E> de::MapAccess<'de> for MapDeserializer<'de, I, E>
where where
I: Iterator, I: Iterator,
I::Item: private::Pair, I::Item: private::Pair,
@@ -757,7 +757,7 @@ where
{ {
type Error = E; type Error = E;
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -770,18 +770,18 @@ where
} }
} }
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error> fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
let value = self.value.take(); let value = self.value.take();
// Panic because this indicates a bug in the program rather than an // Panic because this indicates a bug in the program rather than an
// expected failure. // expected failure.
let value = value.expect("MapVisitor::visit_value called before visit_key"); let value = value.expect("MapAccess::visit_value called before visit_key");
seed.deserialize(value.into_deserializer()) seed.deserialize(value.into_deserializer())
} }
fn visit_seed<TK, TV>(&mut self, fn next_entry_seed<TK, TV>(&mut self,
kseed: TK, kseed: TK,
vseed: TV) vseed: TV)
-> Result<Option<(TK::Value, TV::Value)>, Self::Error> -> Result<Option<(TK::Value, TV::Value)>, Self::Error>
@@ -804,7 +804,7 @@ where
} }
} }
impl<'de, I, E> de::SeqVisitor<'de> for MapDeserializer<'de, I, E> impl<'de, I, E> de::SeqAccess<'de> for MapDeserializer<'de, I, E>
where where
I: Iterator, I: Iterator,
I::Item: private::Pair, I::Item: private::Pair,
@@ -814,7 +814,7 @@ where
{ {
type Error = E; type Error = E;
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -876,7 +876,7 @@ where
} }
} }
// Used in the `impl SeqVisitor for MapDeserializer` to visit the map as a // Used in the `impl SeqAccess for MapDeserializer` to visit the map as a
// sequence of pairs. // sequence of pairs.
struct PairDeserializer<A, B, E>(A, B, PhantomData<E>); struct PairDeserializer<A, B, E>(A, B, PhantomData<E>);
@@ -933,7 +933,7 @@ where
struct PairVisitor<A, B, E>(Option<A>, Option<B>, PhantomData<E>); struct PairVisitor<A, B, E>(Option<A>, Option<B>, PhantomData<E>);
impl<'de, A, B, E> de::SeqVisitor<'de> for PairVisitor<A, B, E> impl<'de, A, B, E> de::SeqAccess<'de> for PairVisitor<A, B, E>
where where
A: IntoDeserializer<'de, E>, A: IntoDeserializer<'de, E>,
B: IntoDeserializer<'de, E>, B: IntoDeserializer<'de, E>,
@@ -941,7 +941,7 @@ where
{ {
type Error = E; type Error = E;
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1010,7 +1010,7 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a map using a `MapVisitor`. /// A helper deserializer that deserializes a map using a `MapAccess`.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MapVisitorDeserializer<V_> { pub struct MapVisitorDeserializer<V_> {
visitor: V_, visitor: V_,
@@ -1025,7 +1025,7 @@ impl<V_> MapVisitorDeserializer<V_> {
impl<'de, V_> de::Deserializer<'de> for MapVisitorDeserializer<V_> impl<'de, V_> de::Deserializer<'de> for MapVisitorDeserializer<V_>
where where
V_: de::MapVisitor<'de>, V_: de::MapAccess<'de>,
{ {
type Error = V_::Error; type Error = V_::Error;
@@ -1059,31 +1059,31 @@ mod private {
(t, UnitOnly { marker: PhantomData }) (t, UnitOnly { marker: PhantomData })
} }
impl<'de, E> de::VariantVisitor<'de> for UnitOnly<E> impl<'de, E> de::VariantAccess<'de> for UnitOnly<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_unit(self) -> Result<(), Self::Error> { fn deserialize_unit(self) -> Result<(), Self::Error> {
Ok(()) Ok(())
} }
fn visit_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error> fn deserialize_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"newtype variant"),) Err(de::Error::invalid_type(Unexpected::UnitVariant, &"newtype variant"),)
} }
fn visit_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error> fn deserialize_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
where where
V: de::Visitor<'de>, V: de::Visitor<'de>,
{ {
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"tuple variant"),) Err(de::Error::invalid_type(Unexpected::UnitVariant, &"tuple variant"),)
} }
fn visit_struct<V>( fn deserialize_struct<V>(
self, self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
_visitor: V, _visitor: V,
+39 -39
View File
@@ -201,8 +201,8 @@ mod content {
use lib::*; use lib::*;
use de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqVisitor, MapVisitor, use de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess, MapAccess,
EnumVisitor, Unexpected}; EnumAccess, Unexpected};
/// Used from generated code to buffer the contents of the Deserializer when /// Used from generated code to buffer the contents of the Deserializer when
/// deserializing untagged enums and internally tagged enums. /// deserializing untagged enums and internally tagged enums.
@@ -426,10 +426,10 @@ mod content {
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
where where
V: SeqVisitor<'de>, V: SeqAccess<'de>,
{ {
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096)); let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
while let Some(e) = try!(visitor.visit()) { while let Some(e) = try!(visitor.next_element()) {
vec.push(e); vec.push(e);
} }
Ok(Content::Seq(vec)) Ok(Content::Seq(vec))
@@ -437,10 +437,10 @@ mod content {
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
where where
V: MapVisitor<'de>, V: MapAccess<'de>,
{ {
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096)); let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
while let Some(kv) = try!(visitor.visit()) { while let Some(kv) = try!(visitor.next_entry()) {
vec.push(kv); vec.push(kv);
} }
Ok(Content::Map(vec)) Ok(Content::Map(vec))
@@ -448,7 +448,7 @@ mod content {
fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error> fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error>
where where
V: EnumVisitor<'de>, V: EnumAccess<'de>,
{ {
Err(de::Error::custom("untagged and internally tagged enums do not support enum input",),) Err(de::Error::custom("untagged and internally tagged enums do not support enum input",),)
} }
@@ -682,7 +682,7 @@ mod content {
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error>
where where
V: SeqVisitor<'de>, V: SeqAccess<'de>,
{ {
ContentVisitor ContentVisitor
.visit_seq(visitor) .visit_seq(visitor)
@@ -691,7 +691,7 @@ mod content {
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error>
where where
V: MapVisitor<'de>, V: MapAccess<'de>,
{ {
ContentVisitor ContentVisitor
.visit_map(visitor) .visit_map(visitor)
@@ -700,7 +700,7 @@ mod content {
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error> fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
where where
V: EnumVisitor<'de>, V: EnumAccess<'de>,
{ {
ContentVisitor ContentVisitor
.visit_enum(visitor) .visit_enum(visitor)
@@ -761,21 +761,21 @@ mod content {
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
where where
V: MapVisitor<'de>, V: MapAccess<'de>,
{ {
let mut tag = None; let mut tag = None;
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096)); let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
while let Some(k) = while let Some(k) =
try!(visitor.visit_key_seed(TagOrContentVisitor::new(self.tag_name))) { try!(visitor.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
match k { match k {
TagOrContent::Tag => { TagOrContent::Tag => {
if tag.is_some() { if tag.is_some() {
return Err(de::Error::duplicate_field(self.tag_name)); return Err(de::Error::duplicate_field(self.tag_name));
} }
tag = Some(try!(visitor.visit_value())); tag = Some(try!(visitor.next_value()));
} }
TagOrContent::Content(k) => { TagOrContent::Content(k) => {
let v = try!(visitor.visit_value()); let v = try!(visitor.next_value());
vec.push((k, v)); vec.push((k, v));
} }
} }
@@ -995,14 +995,14 @@ mod content {
err: PhantomData<E>, err: PhantomData<E>,
} }
impl<'de, E> de::EnumVisitor<'de> for EnumDeserializer<E> impl<'de, E> de::EnumAccess<'de> for EnumDeserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = VariantDeserializer<Self::Error>; type Variant = VariantDeserializer<Self::Error>;
fn visit_variant_seed<V>( fn variant_seed<V>(
self, self,
seed: V, seed: V,
) -> Result<(V::Value, VariantDeserializer<E>), Self::Error> ) -> Result<(V::Value, VariantDeserializer<E>), Self::Error>
@@ -1026,20 +1026,20 @@ mod content {
err: PhantomData<E>, err: PhantomData<E>,
} }
impl<'de, E> de::VariantVisitor<'de> for VariantDeserializer<E> impl<'de, E> de::VariantAccess<'de> for VariantDeserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_unit(self) -> Result<(), E> { fn deserialize_unit(self) -> Result<(), E> {
match self.value { match self.value {
Some(value) => de::Deserialize::deserialize(ContentDeserializer::new(value)), Some(value) => de::Deserialize::deserialize(ContentDeserializer::new(value)),
None => Ok(()), None => Ok(()),
} }
} }
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, E> fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1051,7 +1051,7 @@ mod content {
} }
} }
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error> fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
where where
V: de::Visitor<'de>, V: de::Visitor<'de>,
{ {
@@ -1064,7 +1064,7 @@ mod content {
} }
} }
fn visit_struct<V>( fn deserialize_struct<V>(
self, self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
visitor: V, visitor: V,
@@ -1134,13 +1134,13 @@ mod content {
} }
} }
impl<'de, E> de::SeqVisitor<'de> for SeqDeserializer<E> impl<'de, E> de::SeqAccess<'de> for SeqDeserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1180,13 +1180,13 @@ mod content {
} }
} }
impl<'de, E> de::MapVisitor<'de> for MapDeserializer<E> impl<'de, E> de::MapAccess<'de> for MapDeserializer<E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1199,7 +1199,7 @@ mod content {
} }
} }
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error> fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1391,14 +1391,14 @@ mod content {
err: PhantomData<E>, err: PhantomData<E>,
} }
impl<'de, 'a, E> de::EnumVisitor<'de> for EnumRefDeserializer<'a, E> impl<'de, 'a, E> de::EnumAccess<'de> for EnumRefDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
type Variant = VariantRefDeserializer<'a, Self::Error>; type Variant = VariantRefDeserializer<'a, Self::Error>;
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error> fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
where where
V: de::DeserializeSeed<'de>, V: de::DeserializeSeed<'de>,
{ {
@@ -1419,20 +1419,20 @@ mod content {
err: PhantomData<E>, err: PhantomData<E>,
} }
impl<'de, 'a, E> de::VariantVisitor<'de> for VariantRefDeserializer<'a, E> impl<'de, 'a, E> de::VariantAccess<'de> for VariantRefDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_unit(self) -> Result<(), E> { fn deserialize_unit(self) -> Result<(), E> {
match self.value { match self.value {
Some(value) => de::Deserialize::deserialize(ContentRefDeserializer::new(value)), Some(value) => de::Deserialize::deserialize(ContentRefDeserializer::new(value)),
None => Ok(()), None => Ok(()),
} }
} }
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, E> fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1444,7 +1444,7 @@ mod content {
} }
} }
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error> fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
where where
V: de::Visitor<'de>, V: de::Visitor<'de>,
{ {
@@ -1457,7 +1457,7 @@ mod content {
} }
} }
fn visit_struct<V>( fn deserialize_struct<V>(
self, self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
visitor: V, visitor: V,
@@ -1527,13 +1527,13 @@ mod content {
} }
} }
impl<'de, 'a, E> de::SeqVisitor<'de> for SeqRefDeserializer<'a, E> impl<'de, 'a, E> de::SeqAccess<'de> for SeqRefDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1573,13 +1573,13 @@ mod content {
} }
} }
impl<'de, 'a, E> de::MapVisitor<'de> for MapRefDeserializer<'a, E> impl<'de, 'a, E> de::MapAccess<'de> for MapRefDeserializer<'a, E>
where where
E: de::Error, E: de::Error,
{ {
type Error = E; type Error = E;
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error> fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1593,7 +1593,7 @@ mod content {
} }
} }
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error> fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
where where
T: de::DeserializeSeed<'de>, T: de::DeserializeSeed<'de>,
{ {
@@ -1678,7 +1678,7 @@ mod content {
fn visit_map<V>(self, _: V) -> Result<(), V::Error> fn visit_map<V>(self, _: V) -> Result<(), V::Error>
where where
V: MapVisitor<'de>, V: MapAccess<'de>,
{ {
Ok(()) Ok(())
} }
+51 -51
View File
@@ -292,7 +292,7 @@ fn deserialize_tuple(
let dispatch = if let Some(deserializer) = deserializer { let dispatch = if let Some(deserializer) = deserializer {
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr)) quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
} else if is_enum { } else if is_enum {
quote!(_serde::de::VariantVisitor::visit_tuple(__visitor, #nfields, #visitor_expr)) quote!(_serde::de::VariantAccess::deserialize_tuple(__variant, #nfields, #visitor_expr))
} else if nfields == 1 { } else if nfields == 1 {
let type_name = item_attrs.name().deserialize_name(); let type_name = item_attrs.name().deserialize_name();
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr)) quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
@@ -307,7 +307,7 @@ fn deserialize_tuple(
let visitor_var = if all_skipped { let visitor_var = if all_skipped {
quote!(_) quote!(_)
} else { } else {
quote!(mut __visitor) quote!(mut __seq)
}; };
quote_block! { quote_block! {
@@ -326,8 +326,8 @@ fn deserialize_tuple(
#visit_newtype_struct #visit_newtype_struct
#[inline] #[inline]
fn visit_seq<__V>(self, #visitor_var: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::SeqVisitor<'de> where __A: _serde::de::SeqAccess<'de>
{ {
#visit_seq #visit_seq
} }
@@ -364,7 +364,7 @@ fn deserialize_seq(
let visit = match field.attrs.deserialize_with() { let visit = match field.attrs.deserialize_with() {
None => { None => {
let field_ty = &field.ty; let field_ty = &field.ty;
quote!(try!(_serde::de::SeqVisitor::visit::<#field_ty>(&mut __visitor))) quote!(try!(_serde::de::SeqAccess::next_element::<#field_ty>(&mut __seq)))
} }
Some(path) => { Some(path) => {
let (wrapper, wrapper_ty) = wrap_deserialize_with( let (wrapper, wrapper_ty) = wrap_deserialize_with(
@@ -372,7 +372,7 @@ fn deserialize_seq(
quote!({ quote!({
#wrapper #wrapper
_serde::export::Option::map( _serde::export::Option::map(
try!(_serde::de::SeqVisitor::visit::<#wrapper_ty>(&mut __visitor)), try!(_serde::de::SeqAccess::next_element::<#wrapper_ty>(&mut __seq)),
|__wrap| __wrap.value) |__wrap| __wrap.value)
}) })
} }
@@ -501,7 +501,7 @@ fn deserialize_struct(
} }
} else if is_enum { } else if is_enum {
quote! { quote! {
_serde::de::VariantVisitor::visit_struct(__visitor, FIELDS, #visitor_expr) _serde::de::VariantAccess::deserialize_struct(__variant, FIELDS, #visitor_expr)
} }
} else { } else {
let type_name = item_attrs.name().deserialize_name(); let type_name = item_attrs.name().deserialize_name();
@@ -516,7 +516,7 @@ fn deserialize_struct(
let visitor_var = if all_skipped { let visitor_var = if all_skipped {
quote!(_) quote!(_)
} else { } else {
quote!(mut __visitor) quote!(mut __seq)
}; };
let visit_seq = if is_untagged { let visit_seq = if is_untagged {
@@ -525,8 +525,8 @@ fn deserialize_struct(
} else { } else {
Some(quote! { Some(quote! {
#[inline] #[inline]
fn visit_seq<__V>(self, #visitor_var: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::SeqVisitor<'de> where __A: _serde::de::SeqAccess<'de>
{ {
#visit_seq #visit_seq
} }
@@ -551,8 +551,8 @@ fn deserialize_struct(
#visit_seq #visit_seq
#[inline] #[inline]
fn visit_map<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::MapVisitor<'de> where __A: _serde::de::MapAccess<'de>
{ {
#visit_map #visit_map
} }
@@ -624,7 +624,7 @@ fn deserialize_externally_tagged_enum(
Match(deserialize_externally_tagged_variant(params, variant, item_attrs),); Match(deserialize_externally_tagged_variant(params, variant, item_attrs),);
quote! { quote! {
(__Field::#variant_name, __visitor) => #block (__Field::#variant_name, __variant) => #block
} }
}, },
); );
@@ -637,15 +637,15 @@ fn deserialize_externally_tagged_enum(
// all variants have `#[serde(skip_deserializing)]`. // all variants have `#[serde(skip_deserializing)]`.
quote! { quote! {
// FIXME: Once we drop support for Rust 1.15: // FIXME: Once we drop support for Rust 1.15:
// let _serde::export::Err(__err) = _serde::de::EnumVisitor::visit_variant::<__Field>(__visitor); // let _serde::export::Err(__err) = _serde::de::EnumAccess::variant::<__Field>(__data);
// _serde::export::Err(__err) // _serde::export::Err(__err)
_serde::export::Result::map( _serde::export::Result::map(
_serde::de::EnumVisitor::visit_variant::<__Field>(__visitor), _serde::de::EnumAccess::variant::<__Field>(__data),
|(__impossible, _)| match __impossible {}) |(__impossible, _)| match __impossible {})
} }
} else { } else {
quote! { quote! {
match try!(_serde::de::EnumVisitor::visit_variant(__visitor)) { match try!(_serde::de::EnumAccess::variant(__data)) {
#(#variant_arms)* #(#variant_arms)*
} }
} }
@@ -666,8 +666,8 @@ fn deserialize_externally_tagged_enum(
_serde::export::Formatter::write_str(formatter, #expecting) _serde::export::Formatter::write_str(formatter, #expecting)
} }
fn visit_enum<__V>(self, __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_enum<__A>(self, __data: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::EnumVisitor<'de> where __A: _serde::de::EnumAccess<'de>
{ {
#match_variant #match_variant
} }
@@ -807,7 +807,7 @@ fn deserialize_adjacently_tagged_enum(
} }
let mut missing_content = quote! { let mut missing_content = quote! {
_serde::export::Err(<__V::Error as _serde::de::Error>::missing_field(#content)) _serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
}; };
if variants.iter().any(is_unit) { if variants.iter().any(is_unit) {
let fallthrough = if variants.iter().all(is_unit) { let fallthrough = if variants.iter().all(is_unit) {
@@ -842,12 +842,12 @@ fn deserialize_adjacently_tagged_enum(
let visit_third_key = quote! { let visit_third_key = quote! {
// Visit the third key in the map, hopefully there isn't one. // Visit the third key in the map, hopefully there isn't one.
match try!(_serde::de::MapVisitor::visit_key_seed(&mut __visitor, #tag_or_content)) { match try!(_serde::de::MapAccess::next_key_seed(&mut __map, #tag_or_content)) {
_serde::export::Some(_serde::private::de::TagOrContentField::Tag) => { _serde::export::Some(_serde::private::de::TagOrContentField::Tag) => {
_serde::export::Err(<__V::Error as _serde::de::Error>::duplicate_field(#tag)) _serde::export::Err(<__A::Error as _serde::de::Error>::duplicate_field(#tag))
} }
_serde::export::Some(_serde::private::de::TagOrContentField::Content) => { _serde::export::Some(_serde::private::de::TagOrContentField::Content) => {
_serde::export::Err(<__V::Error as _serde::de::Error>::duplicate_field(#content)) _serde::export::Err(<__A::Error as _serde::de::Error>::duplicate_field(#content))
} }
_serde::export::None => _serde::export::Ok(__ret), _serde::export::None => _serde::export::Ok(__ret),
} }
@@ -888,24 +888,24 @@ fn deserialize_adjacently_tagged_enum(
_serde::export::Formatter::write_str(formatter, #expecting) _serde::export::Formatter::write_str(formatter, #expecting)
} }
fn visit_map<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_map<__A>(self, mut __map: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::MapVisitor<'de> where __A: _serde::de::MapAccess<'de>
{ {
// Visit the first key. // Visit the first key.
match try!(_serde::de::MapVisitor::visit_key_seed(&mut __visitor, #tag_or_content)) { match try!(_serde::de::MapAccess::next_key_seed(&mut __map, #tag_or_content)) {
// First key is the tag. // First key is the tag.
_serde::export::Some(_serde::private::de::TagOrContentField::Tag) => { _serde::export::Some(_serde::private::de::TagOrContentField::Tag) => {
// Parse the tag. // Parse the tag.
let __field = try!(_serde::de::MapVisitor::visit_value(&mut __visitor)); let __field = try!(_serde::de::MapAccess::next_value(&mut __map));
// Visit the second key. // Visit the second key.
match try!(_serde::de::MapVisitor::visit_key_seed(&mut __visitor, #tag_or_content)) { match try!(_serde::de::MapAccess::next_key_seed(&mut __map, #tag_or_content)) {
// Second key is a duplicate of the tag. // Second key is a duplicate of the tag.
_serde::export::Some(_serde::private::de::TagOrContentField::Tag) => { _serde::export::Some(_serde::private::de::TagOrContentField::Tag) => {
_serde::export::Err(<__V::Error as _serde::de::Error>::duplicate_field(#tag)) _serde::export::Err(<__A::Error as _serde::de::Error>::duplicate_field(#tag))
} }
// Second key is the content. // Second key is the content.
_serde::export::Some(_serde::private::de::TagOrContentField::Content) => { _serde::export::Some(_serde::private::de::TagOrContentField::Content) => {
let __ret = try!(_serde::de::MapVisitor::visit_value_seed(&mut __visitor, let __ret = try!(_serde::de::MapAccess::next_value_seed(&mut __map,
__Seed { __Seed {
field: __field, field: __field,
marker: _serde::export::PhantomData, marker: _serde::export::PhantomData,
@@ -921,14 +921,14 @@ fn deserialize_adjacently_tagged_enum(
// First key is the content. // First key is the content.
_serde::export::Some(_serde::private::de::TagOrContentField::Content) => { _serde::export::Some(_serde::private::de::TagOrContentField::Content) => {
// Buffer up the content. // Buffer up the content.
let __content = try!(_serde::de::MapVisitor::visit_value::<_serde::private::de::Content>(&mut __visitor)); let __content = try!(_serde::de::MapAccess::next_value::<_serde::private::de::Content>(&mut __map));
// Visit the second key. // Visit the second key.
match try!(_serde::de::MapVisitor::visit_key_seed(&mut __visitor, #tag_or_content)) { match try!(_serde::de::MapAccess::next_key_seed(&mut __map, #tag_or_content)) {
// Second key is the tag. // Second key is the tag.
_serde::export::Some(_serde::private::de::TagOrContentField::Tag) => { _serde::export::Some(_serde::private::de::TagOrContentField::Tag) => {
let __deserializer = _serde::private::de::ContentDeserializer::<__V::Error>::new(__content); let __deserializer = _serde::private::de::ContentDeserializer::<__A::Error>::new(__content);
// Parse the tag. // Parse the tag.
let __ret = try!(match try!(_serde::de::MapVisitor::visit_value(&mut __visitor)) { let __ret = try!(match try!(_serde::de::MapAccess::next_value(&mut __map)) {
// Deserialize the buffered content now that we know the variant. // Deserialize the buffered content now that we know the variant.
#(#variant_arms)* #(#variant_arms)*
}); });
@@ -937,29 +937,29 @@ fn deserialize_adjacently_tagged_enum(
} }
// Second key is a duplicate of the content. // Second key is a duplicate of the content.
_serde::export::Some(_serde::private::de::TagOrContentField::Content) => { _serde::export::Some(_serde::private::de::TagOrContentField::Content) => {
_serde::export::Err(<__V::Error as _serde::de::Error>::duplicate_field(#content)) _serde::export::Err(<__A::Error as _serde::de::Error>::duplicate_field(#content))
} }
// There is no second key. // There is no second key.
_serde::export::None => { _serde::export::None => {
_serde::export::Err(<__V::Error as _serde::de::Error>::missing_field(#tag)) _serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#tag))
} }
} }
} }
// There is no first key. // There is no first key.
_serde::export::None => { _serde::export::None => {
_serde::export::Err(<__V::Error as _serde::de::Error>::missing_field(#tag)) _serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#tag))
} }
} }
} }
fn visit_seq<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error> fn visit_seq<__A>(self, mut __seq: __A) -> _serde::export::Result<Self::Value, __A::Error>
where __V: _serde::de::SeqVisitor<'de> where __A: _serde::de::SeqAccess<'de>
{ {
// Visit the first element - the tag. // Visit the first element - the tag.
match try!(_serde::de::SeqVisitor::visit(&mut __visitor)) { match try!(_serde::de::SeqAccess::next_element(&mut __seq)) {
_serde::export::Some(__field) => { _serde::export::Some(__field) => {
// Visit the second element - the content. // Visit the second element - the content.
match try!(_serde::de::SeqVisitor::visit_seed(&mut __visitor, match try!(_serde::de::SeqAccess::next_element_seed(&mut __seq,
__Seed { __Seed {
field: __field, field: __field,
marker: _serde::export::PhantomData, marker: _serde::export::PhantomData,
@@ -1041,7 +1041,7 @@ fn deserialize_externally_tagged_variant(
Style::Unit => { Style::Unit => {
let this = &params.this; let this = &params.this;
quote_block! { quote_block! {
try!(_serde::de::VariantVisitor::visit_unit(__visitor)); try!(_serde::de::VariantAccess::deserialize_unit(__variant));
_serde::export::Ok(#this::#variant_ident) _serde::export::Ok(#this::#variant_ident)
} }
} }
@@ -1156,7 +1156,7 @@ fn deserialize_externally_tagged_newtype_variant(
let field_ty = &field.ty; let field_ty = &field.ty;
quote_expr! { quote_expr! {
_serde::export::Result::map( _serde::export::Result::map(
_serde::de::VariantVisitor::visit_newtype::<#field_ty>(__visitor), _serde::de::VariantAccess::deserialize_newtype::<#field_ty>(__variant),
#this::#variant_ident) #this::#variant_ident)
} }
} }
@@ -1165,7 +1165,7 @@ fn deserialize_externally_tagged_newtype_variant(
quote_block! { quote_block! {
#wrapper #wrapper
_serde::export::Result::map( _serde::export::Result::map(
_serde::de::VariantVisitor::visit_newtype::<#wrapper_ty>(__visitor), _serde::de::VariantAccess::deserialize_newtype::<#wrapper_ty>(__variant),
|__wrapper| #this::#variant_ident(__wrapper.value)) |__wrapper| #this::#variant_ident(__wrapper.value))
} }
} }
@@ -1380,7 +1380,7 @@ fn deserialize_map(
None => { None => {
let field_ty = &field.ty; let field_ty = &field.ty;
quote! { quote! {
try!(_serde::de::MapVisitor::visit_value::<#field_ty>(&mut __visitor)) try!(_serde::de::MapAccess::next_value::<#field_ty>(&mut __map))
} }
} }
Some(path) => { Some(path) => {
@@ -1388,14 +1388,14 @@ fn deserialize_map(
params, field.ty, path); params, field.ty, path);
quote!({ quote!({
#wrapper #wrapper
try!(_serde::de::MapVisitor::visit_value::<#wrapper_ty>(&mut __visitor)).value try!(_serde::de::MapAccess::next_value::<#wrapper_ty>(&mut __map)).value
}) })
} }
}; };
quote! { quote! {
__Field::#name => { __Field::#name => {
if _serde::export::Option::is_some(&#name) { if _serde::export::Option::is_some(&#name) {
return _serde::export::Err(<__V::Error as _serde::de::Error>::duplicate_field(#deser_name)); return _serde::export::Err(<__A::Error as _serde::de::Error>::duplicate_field(#deser_name));
} }
#name = _serde::export::Some(#visit); #name = _serde::export::Some(#visit);
} }
@@ -1407,7 +1407,7 @@ fn deserialize_map(
None None
} else { } else {
Some(quote! { Some(quote! {
_ => { let _ = try!(_serde::de::MapVisitor::visit_value::<_serde::de::IgnoredAny>(&mut __visitor)); } _ => { let _ = try!(_serde::de::MapAccess::next_value::<_serde::de::IgnoredAny>(&mut __map)); }
}) })
}; };
@@ -1417,14 +1417,14 @@ fn deserialize_map(
let match_keys = if item_attrs.deny_unknown_fields() && all_skipped { let match_keys = if item_attrs.deny_unknown_fields() && all_skipped {
quote! { quote! {
// FIXME: Once we drop support for Rust 1.15: // FIXME: Once we drop support for Rust 1.15:
// let _serde::export::None::<__Field> = try!(_serde::de::MapVisitor::visit_key(&mut __visitor)); // let _serde::export::None::<__Field> = try!(_serde::de::MapAccess::next_key(&mut __map));
_serde::export::Option::map( _serde::export::Option::map(
try!(_serde::de::MapVisitor::visit_key::<__Field>(&mut __visitor)), try!(_serde::de::MapAccess::next_key::<__Field>(&mut __map)),
|__impossible| match __impossible {}); |__impossible| match __impossible {});
} }
} else { } else {
quote! { quote! {
while let _serde::export::Some(__key) = try!(_serde::de::MapVisitor::visit_key::<__Field>(&mut __visitor)) { while let _serde::export::Some(__key) = try!(_serde::de::MapAccess::next_key::<__Field>(&mut __map)) {
match __key { match __key {
#(#value_arms)* #(#value_arms)*
#ignored_arm #ignored_arm
@@ -1577,7 +1577,7 @@ fn expr_is_missing(field: &Field, item_attrs: &attr::Item) -> Fragment {
} }
Some(_) => { Some(_) => {
quote_expr! { quote_expr! {
return _serde::export::Err(<__V::Error as _serde::de::Error>::missing_field(#name)) return _serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#name))
} }
} }
} }
+17 -17
View File
@@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use serde::de::{self, Deserialize, DeserializeSeed, EnumVisitor, IntoDeserializer, MapVisitor, use serde::de::{self, Deserialize, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess,
SeqVisitor, VariantVisitor, Visitor}; SeqAccess, VariantAccess, Visitor};
use serde::de::value::{MapVisitorDeserializer, SeqVisitorDeserializer}; use serde::de::value::{MapVisitorDeserializer, SeqVisitorDeserializer};
use error::Error; use error::Error;
@@ -390,10 +390,10 @@ struct DeserializerSeqVisitor<'a, 'de: 'a> {
end: Token, end: Token,
} }
impl<'de, 'a> SeqVisitor<'de> for DeserializerSeqVisitor<'a, 'de> { impl<'de, 'a> SeqAccess<'de> for DeserializerSeqVisitor<'a, 'de> {
type Error = Error; type Error = Error;
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error> fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error>
where where
T: DeserializeSeed<'de>, T: DeserializeSeed<'de>,
{ {
@@ -418,10 +418,10 @@ struct DeserializerMapVisitor<'a, 'de: 'a> {
end: Token, end: Token,
} }
impl<'de, 'a> MapVisitor<'de> for DeserializerMapVisitor<'a, 'de> { impl<'de, 'a> MapAccess<'de> for DeserializerMapVisitor<'a, 'de> {
type Error = Error; type Error = Error;
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
where where
K: DeserializeSeed<'de>, K: DeserializeSeed<'de>,
{ {
@@ -432,7 +432,7 @@ impl<'de, 'a> MapVisitor<'de> for DeserializerMapVisitor<'a, 'de> {
seed.deserialize(&mut *self.de).map(Some) seed.deserialize(&mut *self.de).map(Some)
} }
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
where where
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {
@@ -451,11 +451,11 @@ struct DeserializerEnumVisitor<'a, 'de: 'a> {
de: &'a mut Deserializer<'de>, de: &'a mut Deserializer<'de>,
} }
impl<'de, 'a> EnumVisitor<'de> for DeserializerEnumVisitor<'a, 'de> { impl<'de, 'a> EnumAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
type Error = Error; type Error = Error;
type Variant = Self; type Variant = Self;
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self), Error> fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self), Error>
where where
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {
@@ -477,10 +477,10 @@ impl<'de, 'a> EnumVisitor<'de> for DeserializerEnumVisitor<'a, 'de> {
} }
} }
impl<'de, 'a> VariantVisitor<'de> for DeserializerEnumVisitor<'a, 'de> { impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
type Error = Error; type Error = Error;
fn visit_unit(self) -> Result<(), Error> { fn deserialize_unit(self) -> Result<(), Error> {
match self.de.tokens.first() { match self.de.tokens.first() {
Some(&Token::UnitVariant(_, _)) => { Some(&Token::UnitVariant(_, _)) => {
self.de.next_token(); self.de.next_token();
@@ -491,7 +491,7 @@ impl<'de, 'a> VariantVisitor<'de> for DeserializerEnumVisitor<'a, 'de> {
} }
} }
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> fn deserialize_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
where where
T: DeserializeSeed<'de>, T: DeserializeSeed<'de>,
{ {
@@ -505,7 +505,7 @@ impl<'de, 'a> VariantVisitor<'de> for DeserializerEnumVisitor<'a, 'de> {
} }
} }
fn visit_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error> fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
where where
V: Visitor<'de>, V: Visitor<'de>,
{ {
@@ -534,7 +534,7 @@ impl<'de, 'a> VariantVisitor<'de> for DeserializerEnumVisitor<'a, 'de> {
} }
} }
fn visit_struct<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error> fn deserialize_struct<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error>
where where
V: Visitor<'de>, V: Visitor<'de>,
{ {
@@ -589,10 +589,10 @@ impl<'a, 'de> EnumMapVisitor<'a, 'de> {
} }
} }
impl<'de, 'a> MapVisitor<'de> for EnumMapVisitor<'a, 'de> { impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
type Error = Error; type Error = Error;
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
where where
K: DeserializeSeed<'de>, K: DeserializeSeed<'de>,
{ {
@@ -608,7 +608,7 @@ impl<'de, 'a> MapVisitor<'de> for EnumMapVisitor<'a, 'de> {
} }
} }
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
where where
V: DeserializeSeed<'de>, V: DeserializeSeed<'de>,
{ {