mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 14:37:55 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 184264ee92 | |||
| 6050229e7e | |||
| e1db820c9f | |||
| 0081cc961d | |||
| 9bc05803fe |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.38" # remember to update html_root_url
|
version = "1.0.39" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
+4
-10
@@ -652,11 +652,8 @@ where
|
|||||||
{
|
{
|
||||||
/// Check for remaining elements after passing a `SeqDeserializer` to
|
/// Check for remaining elements after passing a `SeqDeserializer` to
|
||||||
/// `Visitor::visit_seq`.
|
/// `Visitor::visit_seq`.
|
||||||
pub fn end(mut self) -> Result<(), E> {
|
pub fn end(self) -> Result<(), E> {
|
||||||
let mut remaining = 0;
|
let remaining = self.iter.count();
|
||||||
while self.iter.next().is_some() {
|
|
||||||
remaining += 1;
|
|
||||||
}
|
|
||||||
if remaining == 0 {
|
if remaining == 0 {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@@ -849,11 +846,8 @@ where
|
|||||||
{
|
{
|
||||||
/// Check for remaining elements after passing a `MapDeserializer` to
|
/// Check for remaining elements after passing a `MapDeserializer` to
|
||||||
/// `Visitor::visit_map`.
|
/// `Visitor::visit_map`.
|
||||||
pub fn end(mut self) -> Result<(), E> {
|
pub fn end(self) -> Result<(), E> {
|
||||||
let mut remaining = 0;
|
let remaining = self.iter.count();
|
||||||
while self.iter.next().is_some() {
|
|
||||||
remaining += 1;
|
|
||||||
}
|
|
||||||
if remaining == 0 {
|
if remaining == 0 {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.38")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.39")]
|
||||||
// Support using Serde without the standard library!
|
// Support using Serde without the standard library!
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// Unstable functionality only if the user asks for it. For tracking and
|
// Unstable functionality only if the user asks for it. For tracking and
|
||||||
|
|||||||
+639
-65
@@ -229,8 +229,8 @@ mod content {
|
|||||||
use lib::*;
|
use lib::*;
|
||||||
|
|
||||||
use super::size_hint;
|
use super::size_hint;
|
||||||
use de::{self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, MapAccess, SeqAccess,
|
use de::{self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, MapAccess,
|
||||||
Unexpected, Visitor};
|
SeqAccess, Unexpected, Visitor};
|
||||||
|
|
||||||
/// 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.
|
||||||
@@ -1013,6 +1013,45 @@ mod content {
|
|||||||
err: PhantomData<E>,
|
err: PhantomData<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de, E> ContentDeserializer<'de, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
#[cold]
|
||||||
|
fn invalid_type(self, exp: &Expected) -> E {
|
||||||
|
de::Error::invalid_type(self.content.unexpected(), exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_content_seq<'de, V, E>(content: Vec<Content<'de>>, visitor: V) -> Result<V::Value, E>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
let seq = content.into_iter().map(ContentDeserializer::new);
|
||||||
|
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
||||||
|
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
||||||
|
try!(seq_visitor.end());
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_content_map<'de, V, E>(
|
||||||
|
content: Vec<(Content<'de>, Content<'de>)>,
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, E>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
let map = content
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
||||||
|
let mut map_visitor = de::value::MapDeserializer::new(map);
|
||||||
|
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||||
|
try!(map_visitor.end());
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Used when deserializing an internally tagged enum because the content will
|
/// Used when deserializing an internally tagged enum because the content will
|
||||||
/// be used exactly once.
|
/// be used exactly once.
|
||||||
impl<'de, E> Deserializer<'de> for ContentDeserializer<'de, E>
|
impl<'de, E> Deserializer<'de> for ContentDeserializer<'de, E>
|
||||||
@@ -1046,21 +1085,185 @@ mod content {
|
|||||||
Content::None => visitor.visit_none(),
|
Content::None => visitor.visit_none(),
|
||||||
Content::Some(v) => visitor.visit_some(ContentDeserializer::new(*v)),
|
Content::Some(v) => visitor.visit_some(ContentDeserializer::new(*v)),
|
||||||
Content::Newtype(v) => visitor.visit_newtype_struct(ContentDeserializer::new(*v)),
|
Content::Newtype(v) => visitor.visit_newtype_struct(ContentDeserializer::new(*v)),
|
||||||
Content::Seq(v) => {
|
Content::Seq(v) => visit_content_seq(v, visitor),
|
||||||
let seq = v.into_iter().map(ContentDeserializer::new);
|
Content::Map(v) => visit_content_map(v, visitor),
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
}
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
}
|
||||||
try!(seq_visitor.end());
|
|
||||||
Ok(value)
|
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
}
|
where
|
||||||
Content::Map(v) => {
|
V: Visitor<'de>,
|
||||||
let map = v.into_iter()
|
{
|
||||||
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
match self.content {
|
||||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
Content::Bool(v) => visitor.visit_bool(v),
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
try!(map_visitor.end());
|
}
|
||||||
Ok(value)
|
}
|
||||||
}
|
|
||||||
|
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::I8(v) => visitor.visit_i8(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::I16(v) => visitor.visit_i16(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::I32(v) => visitor.visit_i32(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::U8(v) => visitor.visit_u8(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::U16(v) => visitor.visit_u16(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::U32(v) => visitor.visit_u32(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::F32(v) => visitor.visit_f32(v),
|
||||||
|
Content::F64(v) => visitor.visit_f64(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::F64(v) => visitor.visit_f64(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::Char(v) => visitor.visit_char(v),
|
||||||
|
Content::String(v) => visitor.visit_string(v),
|
||||||
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_string(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::String(v) => visitor.visit_string(v),
|
||||||
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_byte_buf(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::ByteBuf(v) => visitor.visit_byte_buf(v),
|
||||||
|
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1076,6 +1279,44 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::Unit => visitor.visit_unit(),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_unit_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
// As a special case, allow deserializing untagged newtype
|
||||||
|
// variant containing unit struct.
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// struct Info;
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(tag = "topic")]
|
||||||
|
// enum Message {
|
||||||
|
// Info(Info),
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// We want {"topic":"Info"} to deserialize even though
|
||||||
|
// ordinarily unit structs do not deserialize from empty map.
|
||||||
|
Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
|
||||||
|
_ => self.deserialize_any(visitor),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_newtype_struct<V>(
|
fn deserialize_newtype_struct<V>(
|
||||||
self,
|
self,
|
||||||
_name: &str,
|
_name: &str,
|
||||||
@@ -1087,6 +1328,61 @@ mod content {
|
|||||||
visitor.visit_newtype_struct(self)
|
visitor.visit_newtype_struct(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::Seq(v) => visit_content_seq(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_seq(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_tuple_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
_len: usize,
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_seq(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::Map(v) => visit_content_map(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
_fields: &'static [&'static str],
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match self.content {
|
||||||
|
Content::Seq(v) => visit_content_seq(v, visitor),
|
||||||
|
Content::Map(v) => visit_content_map(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_enum<V>(
|
fn deserialize_enum<V>(
|
||||||
self,
|
self,
|
||||||
_name: &str,
|
_name: &str,
|
||||||
@@ -1129,38 +1425,23 @@ mod content {
|
|||||||
visitor.visit_enum(EnumDeserializer::new(variant, value))
|
visitor.visit_enum(EnumDeserializer::new(variant, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_unit_struct<V>(
|
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
self,
|
|
||||||
_name: &'static str,
|
|
||||||
visitor: V,
|
|
||||||
) -> Result<V::Value, Self::Error>
|
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
match self.content {
|
match self.content {
|
||||||
// As a special case, allow deserializing untagged newtype
|
Content::String(v) => visitor.visit_string(v),
|
||||||
// variant containing unit struct.
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
//
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
// #[derive(Deserialize)]
|
|
||||||
// struct Info;
|
|
||||||
//
|
|
||||||
// #[derive(Deserialize)]
|
|
||||||
// #[serde(tag = "topic")]
|
|
||||||
// enum Message {
|
|
||||||
// Info(Info),
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// We want {"topic":"Info"} to deserialize even though
|
|
||||||
// ordinarily unit structs do not deserialize from empty map.
|
|
||||||
Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
|
|
||||||
_ => self.deserialize_any(visitor),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes
|
where
|
||||||
byte_buf unit seq tuple tuple_struct map struct identifier
|
V: Visitor<'de>,
|
||||||
ignored_any
|
{
|
||||||
|
drop(self);
|
||||||
|
visitor.visit_unit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1452,6 +1733,51 @@ mod content {
|
|||||||
err: PhantomData<E>,
|
err: PhantomData<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
#[cold]
|
||||||
|
fn invalid_type(self, exp: &Expected) -> E {
|
||||||
|
de::Error::invalid_type(self.content.unexpected(), exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_content_seq_ref<'a, 'de, V, E>(
|
||||||
|
content: &'a [Content<'de>],
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, E>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
let seq = content.into_iter().map(ContentRefDeserializer::new);
|
||||||
|
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
||||||
|
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
||||||
|
try!(seq_visitor.end());
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_content_map_ref<'a, 'de, V, E>(
|
||||||
|
content: &'a [(Content<'de>, Content<'de>)],
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, E>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
let map = content.into_iter().map(|&(ref k, ref v)| {
|
||||||
|
(
|
||||||
|
ContentRefDeserializer::new(k),
|
||||||
|
ContentRefDeserializer::new(v),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
let mut map_visitor = de::value::MapDeserializer::new(map);
|
||||||
|
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||||
|
try!(map_visitor.end());
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Used when deserializing an untagged enum because the content may need to be
|
/// Used when deserializing an untagged enum because the content may need to be
|
||||||
/// used more than once.
|
/// used more than once.
|
||||||
impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
|
impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
|
||||||
@@ -1487,28 +1813,188 @@ mod content {
|
|||||||
Content::Newtype(ref v) => {
|
Content::Newtype(ref v) => {
|
||||||
visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
|
visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
|
||||||
}
|
}
|
||||||
Content::Seq(ref v) => {
|
Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
|
||||||
let seq = v.into_iter().map(ContentRefDeserializer::new);
|
Content::Map(ref v) => visit_content_map_ref(v, visitor),
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
|
||||||
try!(seq_visitor.end());
|
|
||||||
Ok(value)
|
|
||||||
}
|
|
||||||
Content::Map(ref v) => {
|
|
||||||
let map = v.into_iter().map(|&(ref k, ref v)| {
|
|
||||||
(
|
|
||||||
ContentRefDeserializer::new(k),
|
|
||||||
ContentRefDeserializer::new(v),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
|
||||||
try!(map_visitor.end());
|
|
||||||
Ok(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Bool(v) => visitor.visit_bool(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::I8(v) => visitor.visit_i8(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::I16(v) => visitor.visit_i16(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::I32(v) => visitor.visit_i32(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::U8(v) => visitor.visit_u8(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::U16(v) => visitor.visit_u16(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::U32(v) => visitor.visit_u32(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::F32(v) => visitor.visit_f32(v),
|
||||||
|
Content::F64(v) => visitor.visit_f64(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::F64(v) => visitor.visit_f64(v),
|
||||||
|
Content::U64(v) => visitor.visit_u64(v),
|
||||||
|
Content::I64(v) => visitor.visit_i64(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Char(v) => visitor.visit_char(v),
|
||||||
|
Content::String(ref v) => visitor.visit_str(v),
|
||||||
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::String(ref v) => visitor.visit_str(v),
|
||||||
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_str(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::ByteBuf(ref v) => visitor.visit_bytes(v),
|
||||||
|
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_bytes(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, E>
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, E>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
@@ -1521,6 +2007,27 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Unit => visitor.visit_unit(),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_unit_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_unit(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, E>
|
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, E>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
@@ -1528,6 +2035,61 @@ mod content {
|
|||||||
visitor.visit_newtype_struct(self)
|
visitor.visit_newtype_struct(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_seq(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_tuple_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
_len: usize,
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
self.deserialize_seq(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Map(ref v) => visit_content_map_ref(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_struct<V>(
|
||||||
|
self,
|
||||||
|
_name: &'static str,
|
||||||
|
_fields: &'static [&'static str],
|
||||||
|
visitor: V,
|
||||||
|
) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
|
||||||
|
Content::Map(ref v) => visit_content_map_ref(v, visitor),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_enum<V>(
|
fn deserialize_enum<V>(
|
||||||
self,
|
self,
|
||||||
_name: &str,
|
_name: &str,
|
||||||
@@ -1574,10 +2136,22 @@ mod content {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes
|
where
|
||||||
byte_buf unit unit_struct seq tuple tuple_struct map struct
|
V: Visitor<'de>,
|
||||||
identifier ignored_any
|
{
|
||||||
|
match *self.content {
|
||||||
|
Content::String(ref v) => visitor.visit_str(v),
|
||||||
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
visitor.visit_unit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.38" # remember to update html_root_url
|
version = "1.0.39" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.38")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.39")]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding)
|
allow(enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.38" # remember to update html_root_url
|
version = "1.0.39" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.38")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.39")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ macro_rules! assert_next_token {
|
|||||||
($ser:expr, $expected:ident($v:expr)) => {
|
($ser:expr, $expected:ident($v:expr)) => {
|
||||||
assert_next_token!(
|
assert_next_token!(
|
||||||
$ser,
|
$ser,
|
||||||
format_args!("{}({:?})", stringify!($expected), $v),
|
format_args!(concat!(stringify!($expected), "({:?})"), $v),
|
||||||
Token::$expected(v),
|
Token::$expected(v),
|
||||||
v == $v
|
v == $v
|
||||||
);
|
);
|
||||||
@@ -56,13 +56,13 @@ macro_rules! assert_next_token {
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
$(
|
$(
|
||||||
write!(&mut buffer, "{}: {:?}, ", stringify!($k), $k).unwrap();
|
write!(&mut buffer, concat!(stringify!($k), ": {:?}, "), $k).unwrap();
|
||||||
)*
|
)*
|
||||||
buffer
|
buffer
|
||||||
};
|
};
|
||||||
assert_next_token!(
|
assert_next_token!(
|
||||||
$ser,
|
$ser,
|
||||||
format_args!("{} {{ {}}}", stringify!($expected), field_format()),
|
format_args!(concat!(stringify!($expected), " {{ {}}}"), field_format()),
|
||||||
Token::$expected { $($k),* },
|
Token::$expected { $($k),* },
|
||||||
($($k,)*) == compare
|
($($k,)*) == compare
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user