Merge pull request #878 from serde-rs/deserialize_any

Rename Deserializer::deserialize to deserialize_any
This commit is contained in:
David Tolnay 2017-04-14 13:04:20 -07:00 committed by GitHub
commit 637332de2d
7 changed files with 116 additions and 116 deletions

View File

@ -1070,7 +1070,7 @@ impl<'de> Deserialize<'de> for OsStringKind {
}
}
deserializer.deserialize(KindVisitor)
deserializer.deserialize_identifier(KindVisitor)
}
}
@ -1581,7 +1581,7 @@ where
}
}
deserializer.deserialize(FieldVisitor)
deserializer.deserialize_identifier(FieldVisitor)
}
}

View File

@ -763,22 +763,22 @@ where
/// to look at the serialized data and tell what it represents. For example
/// the JSON deserializer may see an opening curly brace (`{`) and know that
/// it is seeing a map. If the data format supports
/// `Deserializer::deserialize`, it will drive the Visitor using whatever
/// `Deserializer::deserialize_any`, it will drive the Visitor using whatever
/// type it sees in the input. JSON uses this approach when deserializing
/// `serde_json::Value` which is an enum that can represent any JSON
/// document. Without knowing what is in a JSON document, we can deserialize
/// it to `serde_json::Value` by going through `Deserializer::deserialize`.
/// it to `serde_json::Value` by going through `Deserializer::deserialize_any`.
///
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
/// Bincode need to be told what is in the input in order to deserialize it.
/// The `deserialize_*` methods are hints to the deserializer for how to
/// interpret the next piece of input. Non-self-describing formats are not
/// able to deserialize something like `serde_json::Value` which relies on
/// `Deserializer::deserialize`.
/// `Deserializer::deserialize_any`.
///
/// When implementing `Deserialize`, you should avoid relying on
/// `Deserializer::deserialize` unless you need to be told by the Deserializer
/// what type is in the input. Know that relying on `Deserializer::deserialize`
/// `Deserializer::deserialize_any` unless you need to be told by the Deserializer
/// what type is in the input. Know that relying on `Deserializer::deserialize_any`
/// means your data type will be able to deserialize from self-describing
/// formats only, ruling out Bincode and many others.
pub trait Deserializer<'de>: Sized {
@ -790,12 +790,12 @@ pub trait Deserializer<'de>: Sized {
/// on what data type is in the input.
///
/// When implementing `Deserialize`, you should avoid relying on
/// `Deserializer::deserialize` unless you need to be told by the
/// `Deserializer::deserialize_any` unless you need to be told by the
/// Deserializer what type is in the input. Know that relying on
/// `Deserializer::deserialize` means your data type will be able to
/// `Deserializer::deserialize_any` means your data type will be able to
/// deserialize from self-describing formats only, ruling out Bincode and
/// many others.
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>;

View File

@ -88,13 +88,13 @@ where
{
type Error = E;
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
seq_fixed_size bytes map unit_struct newtype_struct tuple_struct struct
identifier tuple enum ignored_any byte_buf
}
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -140,13 +140,13 @@ macro_rules! primitive_deserializer {
{
type Error = E;
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
option seq seq_fixed_size bytes map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any byte_buf
}
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -197,13 +197,13 @@ where
{
type Error = E;
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple ignored_any byte_buf
}
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -267,7 +267,7 @@ where
{
type Error = E;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -286,7 +286,7 @@ where
visitor.visit_enum(self)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple ignored_any byte_buf
@ -340,7 +340,7 @@ where
{
type Error = E;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -359,7 +359,7 @@ where
visitor.visit_enum(self)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple ignored_any byte_buf
@ -414,7 +414,7 @@ where
{
type Error = E;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -436,7 +436,7 @@ where
visitor.visit_enum(self)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple ignored_any byte_buf
@ -508,7 +508,7 @@ where
{
type Error = E;
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -517,7 +517,7 @@ where
Ok(v)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple enum ignored_any byte_buf
@ -624,14 +624,14 @@ where
{
type Error = V_::Error;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_seq(self.visitor)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple enum ignored_any byte_buf
@ -712,7 +712,7 @@ where
{
type Error = E;
fn deserialize<V_>(mut self, visitor: V_) -> Result<V_::Value, Self::Error>
fn deserialize_any<V_>(mut self, visitor: V_) -> Result<V_::Value, Self::Error>
where
V_: de::Visitor<'de>,
{
@ -740,7 +740,7 @@ where
self.deserialize_seq(visitor)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
bytes map unit_struct newtype_struct tuple_struct struct identifier
tuple enum ignored_any byte_buf
@ -888,13 +888,13 @@ where
{
type Error = E;
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
bytes map unit_struct newtype_struct tuple_struct struct identifier
tuple enum ignored_any byte_buf
}
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -1029,14 +1029,14 @@ where
{
type Error = V_::Error;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_map(self.visitor)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple enum ignored_any byte_buf

View File

@ -30,7 +30,7 @@
/// # impl<'de> Deserializer<'de> for MyDeserializer {
/// # type Error = value::Error;
/// #
/// # fn deserialize<V>(self, _: V) -> Result<V::Value, Self::Error>
/// # fn deserialize_any<V>(self, _: V) -> Result<V::Value, Self::Error>
/// # where V: Visitor<'de>
/// # {
/// # unimplemented!()
@ -40,10 +40,10 @@
/// fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de>
/// {
/// self.deserialize(visitor)
/// self.deserialize_any(visitor)
/// }
/// #
/// # forward_to_deserialize! {
/// # forward_to_deserialize_any! {
/// # u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
/// # seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
/// # tuple_struct struct identifier tuple enum ignored_any
@ -53,9 +53,9 @@
/// # fn main() {}
/// ```
///
/// The `forward_to_deserialize!` macro implements these simple forwarding
/// methods so that they forward directly to [`Deserializer::deserialize`]. You
/// can choose which methods to forward.
/// The `forward_to_deserialize_any!` macro implements these simple forwarding
/// methods so that they forward directly to [`Deserializer::deserialize_any`].
/// You can choose which methods to forward.
///
/// ```rust
/// # #[macro_use]
@ -68,7 +68,7 @@
/// impl<'de> Deserializer<'de> for MyDeserializer {
/// # type Error = value::Error;
/// #
/// fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
/// fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
/// where V: Visitor<'de>
/// {
/// /* ... */
@ -76,7 +76,7 @@
/// # unimplemented!()
/// }
///
/// forward_to_deserialize! {
/// forward_to_deserialize_any! {
/// bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
/// seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
/// tuple_struct struct identifier tuple enum ignored_any
@ -104,13 +104,13 @@
/// # impl<'q, V> Deserializer<'q> for MyDeserializer<V> {
/// # type Error = value::Error;
/// #
/// # fn deserialize<W>(self, visitor: W) -> Result<W::Value, Self::Error>
/// # fn deserialize_any<W>(self, visitor: W) -> Result<W::Value, Self::Error>
/// # where W: Visitor<'q>
/// # {
/// # unimplemented!()
/// # }
/// #
/// forward_to_deserialize! {
/// forward_to_deserialize_any! {
/// <W: Visitor<'q>>
/// bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
/// seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
@ -123,21 +123,21 @@
///
/// [`Deserializer`]: trait.Deserializer.html
/// [`Visitor`]: de/trait.Visitor.html
/// [`Deserializer::deserialize`]: trait.Deserializer.html#tymethod.deserialize
/// [`Deserializer::deserialize_any`]: trait.Deserializer.html#tymethod.deserialize_any
#[macro_export]
macro_rules! forward_to_deserialize {
macro_rules! forward_to_deserialize_any {
(<$visitor:ident: Visitor<$lifetime:tt>> $($func:ident)*) => {
$(forward_to_deserialize_helper!{$func<$lifetime, $visitor>})*
$(forward_to_deserialize_any_helper!{$func<$lifetime, $visitor>})*
};
// This case must be after the previous one.
($($func:ident)*) => {
$(forward_to_deserialize_helper!{$func<'de, V>})*
$(forward_to_deserialize_any_helper!{$func<'de, V>})*
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! forward_to_deserialize_method {
macro_rules! forward_to_deserialize_any_method {
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
#[inline]
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::export::Result<$v::Value, Self::Error>
@ -147,99 +147,99 @@ macro_rules! forward_to_deserialize_method {
$(
let _ = $arg;
)*
self.deserialize(visitor)
self.deserialize_any(visitor)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! forward_to_deserialize_helper {
macro_rules! forward_to_deserialize_any_helper {
(bool<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_bool<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_bool<$l, $v>()}
};
(u8<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_u8<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_u8<$l, $v>()}
};
(u16<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_u16<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_u16<$l, $v>()}
};
(u32<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_u32<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_u32<$l, $v>()}
};
(u64<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_u64<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_u64<$l, $v>()}
};
(i8<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_i8<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_i8<$l, $v>()}
};
(i16<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_i16<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_i16<$l, $v>()}
};
(i32<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_i32<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_i32<$l, $v>()}
};
(i64<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_i64<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_i64<$l, $v>()}
};
(f32<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_f32<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_f32<$l, $v>()}
};
(f64<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_f64<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_f64<$l, $v>()}
};
(char<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_char<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_char<$l, $v>()}
};
(str<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_str<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_str<$l, $v>()}
};
(string<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_string<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_string<$l, $v>()}
};
(unit<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_unit<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_unit<$l, $v>()}
};
(option<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_option<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_option<$l, $v>()}
};
(seq<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_seq<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_seq<$l, $v>()}
};
(seq_fixed_size<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_seq_fixed_size<$l, $v>(len: usize)}
forward_to_deserialize_any_method!{deserialize_seq_fixed_size<$l, $v>(len: usize)}
};
(bytes<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_bytes<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_bytes<$l, $v>()}
};
(byte_buf<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_byte_buf<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_byte_buf<$l, $v>()}
};
(map<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_map<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_map<$l, $v>()}
};
(unit_struct<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_unit_struct<$l, $v>(name: &'static str)}
forward_to_deserialize_any_method!{deserialize_unit_struct<$l, $v>(name: &'static str)}
};
(newtype_struct<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_newtype_struct<$l, $v>(name: &'static str)}
forward_to_deserialize_any_method!{deserialize_newtype_struct<$l, $v>(name: &'static str)}
};
(tuple_struct<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_tuple_struct<$l, $v>(name: &'static str, len: usize)}
forward_to_deserialize_any_method!{deserialize_tuple_struct<$l, $v>(name: &'static str, len: usize)}
};
(struct<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_struct<$l, $v>(name: &'static str, fields: &'static [&'static str])}
forward_to_deserialize_any_method!{deserialize_struct<$l, $v>(name: &'static str, fields: &'static [&'static str])}
};
(identifier<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_identifier<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_identifier<$l, $v>()}
};
(tuple<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_tuple<$l, $v>(len: usize)}
forward_to_deserialize_any_method!{deserialize_tuple<$l, $v>(len: usize)}
};
(enum<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_enum<$l, $v>(name: &'static str, variants: &'static [&'static str])}
forward_to_deserialize_any_method!{deserialize_enum<$l, $v>(name: &'static str, variants: &'static [&'static str])}
};
(ignored_any<$l:tt, $v:ident>) => {
forward_to_deserialize_method!{deserialize_ignored_any<$l, $v>()}
forward_to_deserialize_any_method!{deserialize_ignored_any<$l, $v>()}
};
}

View File

@ -33,7 +33,7 @@ where
{
type Error = E;
fn deserialize<V>(self, _visitor: V) -> Result<V::Value, E>
fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, E>
where
V: Visitor<'de>,
{
@ -47,7 +47,7 @@ where
visitor.visit_none()
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
seq_fixed_size bytes byte_buf map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any
@ -271,7 +271,7 @@ mod content {
{
// Untagged and internally tagged enums are only supported in
// self-describing formats.
deserializer.deserialize(ContentVisitor)
deserializer.deserialize_any(ContentVisitor)
}
}
@ -481,7 +481,7 @@ mod content {
{
// Internally tagged enums are only supported in self-describing
// formats.
deserializer.deserialize(self)
deserializer.deserialize_any(self)
}
}
@ -745,7 +745,7 @@ mod content {
{
// Internally tagged enums are only supported in self-describing
// formats.
deserializer.deserialize(self)
deserializer.deserialize_any(self)
}
}
@ -854,7 +854,7 @@ mod content {
{
type Error = E;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
@ -969,7 +969,7 @@ mod content {
)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
identifier tuple ignored_any
@ -1057,7 +1057,7 @@ mod content {
{
match self.value {
Some(Content::Seq(v)) => {
de::Deserializer::deserialize(SeqDeserializer::new(v), visitor)
de::Deserializer::deserialize_any(SeqDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"tuple variant"),),
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant"),),
@ -1074,7 +1074,7 @@ mod content {
{
match self.value {
Some(Content::Map(v)) => {
de::Deserializer::deserialize(MapDeserializer::new(v), visitor)
de::Deserializer::deserialize_any(MapDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant"),),
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"),),
@ -1109,7 +1109,7 @@ mod content {
type Error = E;
#[inline]
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -1127,7 +1127,7 @@ mod content {
}
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any
@ -1221,14 +1221,14 @@ mod content {
type Error = E;
#[inline]
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_map(self)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any
@ -1250,7 +1250,7 @@ mod content {
{
type Error = E;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, E>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, E>
where
V: Visitor<'de>,
{
@ -1365,7 +1365,7 @@ mod content {
)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
identifier tuple ignored_any
@ -1450,7 +1450,7 @@ mod content {
{
match self.value {
Some(&Content::Seq(ref v)) => {
de::Deserializer::deserialize(SeqRefDeserializer::new(v), visitor)
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"tuple variant"),),
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant"),),
@ -1467,7 +1467,7 @@ mod content {
{
match self.value {
Some(&Content::Map(ref v)) => {
de::Deserializer::deserialize(MapRefDeserializer::new(v), visitor)
de::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant"),),
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"),),
@ -1502,7 +1502,7 @@ mod content {
type Error = E;
#[inline]
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
@ -1520,7 +1520,7 @@ mod content {
}
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any
@ -1615,14 +1615,14 @@ mod content {
type Error = E;
#[inline]
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_map(self)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
tuple_struct struct identifier tuple enum ignored_any

View File

@ -497,7 +497,7 @@ fn deserialize_struct(
};
let dispatch = if let Some(deserializer) = deserializer {
quote! {
_serde::Deserializer::deserialize(#deserializer, #visitor_expr)
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
}
} else if is_enum {
quote! {
@ -729,7 +729,7 @@ fn deserialize_internally_tagged_enum(
#variants_stmt
let __tagged = try!(_serde::Deserializer::deserialize(
let __tagged = try!(_serde::Deserializer::deserialize_any(
__deserializer,
_serde::private::de::TaggedContentVisitor::<__Field>::new(#tag)));
@ -1083,7 +1083,7 @@ fn deserialize_internally_tagged_variant(
let type_name = params.type_name();
let variant_name = variant.ident.as_ref();
quote_block! {
try!(_serde::Deserializer::deserialize(#deserializer, _serde::private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name)));
try!(_serde::Deserializer::deserialize_any(#deserializer, _serde::private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name)));
_serde::export::Ok(#this::#variant_ident)
}
}
@ -1109,7 +1109,7 @@ fn deserialize_untagged_variant(
let variant_name = variant.ident.as_ref();
quote_expr! {
_serde::export::Result::map(
_serde::Deserializer::deserialize(
_serde::Deserializer::deserialize_any(
#deserializer,
_serde::private::de::UntaggedUnitVisitor::new(#type_name, #variant_name)
),

View File

@ -97,12 +97,12 @@ impl<'de> Deserializer<'de> {
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
type Error = Error;
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
seq bytes byte_buf map identifier ignored_any
}
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
@ -192,7 +192,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
self.next_token();
visitor.visit_some(self)
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -239,7 +239,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
Err(Error::InvalidName(n))
}
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -257,7 +257,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
Err(Error::InvalidName(n))
}
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -271,7 +271,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
self.next_token();
self.visit_seq(Some(len), Token::SeqEnd, visitor)
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -302,7 +302,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
self.next_token();
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -349,7 +349,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
Err(Error::InvalidName(n))
}
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -376,7 +376,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
self.next_token();
self.visit_map(Some(fields.len()), Token::MapEnd, visitor)
}
Some(_) => self.deserialize(visitor),
Some(_) => self.deserialize_any(visitor),
None => Err(Error::EndOfTokens),
}
}
@ -529,7 +529,7 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
Err(Error::UnexpectedToken(token))
}
}
Some(_) => de::Deserializer::deserialize(self.de, visitor),
Some(_) => de::Deserializer::deserialize_any(self.de, visitor),
None => Err(Error::EndOfTokens),
}
}
@ -559,7 +559,7 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
Err(Error::UnexpectedToken(token))
}
}
Some(_) => de::Deserializer::deserialize(self.de, visitor),
Some(_) => de::Deserializer::deserialize_any(self.de, visitor),
None => Err(Error::EndOfTokens),
}
}
@ -649,14 +649,14 @@ struct BytesDeserializer {
impl<'de> de::Deserializer<'de> for BytesDeserializer {
type Error = Error;
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_bytes(self.value)
}
forward_to_deserialize! {
forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
struct identifier tuple enum ignored_any byte_buf