mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 14:37:55 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b4803115b | |||
| fa5f0f4541 | |||
| 4b7f55bd42 | |||
| 593bcb087d | |||
| f58000cb41 | |||
| 01b86d5ce4 | |||
| c80f9238d7 | |||
| 62850bf832 | |||
| 9f114548f4 | |||
| 8890061f82 | |||
| 2c05518810 | |||
| 4aeb0df88f | |||
| 6550231a51 | |||
| ea0012fc5a | |||
| d6b62b9417 | |||
| 2ee347c5a5 | |||
| 4305260174 | |||
| 35aae92b56 | |||
| f3f26796c7 | |||
| d1460e1f0d | |||
| dfd81323d5 | |||
| 368961e961 |
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
name: Anything else!
|
||||||
|
about: Whatever is on your mind
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
+3
-7
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.52" # remember to update html_root_url
|
version = "1.0.57" # 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"
|
||||||
@@ -10,7 +10,8 @@ documentation = "https://docs.serde.rs/serde/"
|
|||||||
keywords = ["serde", "serialization", "no_std"]
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
categories = ["encoding"]
|
categories = ["encoding"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
include = ["Cargo.toml", "build.rs", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
@@ -61,8 +62,3 @@ alloc = ["unstable"]
|
|||||||
# does not preserve identity and may result in multiple copies of the same data.
|
# does not preserve identity and may result in multiple copies of the same data.
|
||||||
# Be sure that this is what you want before enabling this feature.
|
# Be sure that this is what you want before enabling this feature.
|
||||||
rc = []
|
rc = []
|
||||||
|
|
||||||
# Get serde_derive picked up by the Integer 32 playground. Not public API.
|
|
||||||
#
|
|
||||||
# http://play.integer32.com/
|
|
||||||
playground = ["serde_derive"]
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::process::Command;
|
||||||
|
use std::str::{self, FromStr};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let rustc = match env::var_os("RUSTC") {
|
||||||
|
Some(rustc) => rustc,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let output = match Command::new(rustc).arg("--version").output() {
|
||||||
|
Ok(output) => output,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let version = match str::from_utf8(&output.stdout) {
|
||||||
|
Ok(version) => version,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut pieces = version.split('.');
|
||||||
|
if pieces.next() != Some("rustc 1") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let next = match pieces.next() {
|
||||||
|
Some(next) => next,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let minor = match u32::from_str(next) {
|
||||||
|
Ok(minor) => minor,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 128-bit integers stabilized in Rust 1.26:
|
||||||
|
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
|
||||||
|
if minor >= 26 {
|
||||||
|
println!("cargo:rustc-cfg=integer128");
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-18
@@ -529,6 +529,14 @@ where
|
|||||||
{
|
{
|
||||||
T::deserialize(deserializer).map(Some)
|
T::deserialize(deserializer).map(Some)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn __private_visit_untagged_option<D>(self, deserializer: D) -> Result<Self::Value, ()>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Ok(T::deserialize(deserializer).ok())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, T> Deserialize<'de> for Option<T>
|
impl<'de, T> Deserialize<'de> for Option<T>
|
||||||
@@ -1997,24 +2005,6 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<'de, T> Deserialize<'de> for NonZero<T>
|
|
||||||
where
|
|
||||||
T: Deserialize<'de> + Zeroable,
|
|
||||||
{
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let value = try!(Deserialize::deserialize(deserializer));
|
|
||||||
match NonZero::new(value) {
|
|
||||||
Some(nonzero) => Ok(nonzero),
|
|
||||||
None => Err(Error::custom("expected a non-zero value")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
( $( $T: ty, )+ ) => {
|
( $( $T: ty, )+ ) => {
|
||||||
$(
|
$(
|
||||||
|
|||||||
+9
-14
@@ -84,7 +84,6 @@
|
|||||||
//! - LinkedList\<T\>
|
//! - LinkedList\<T\>
|
||||||
//! - VecDeque\<T\>
|
//! - VecDeque\<T\>
|
||||||
//! - Vec\<T\>
|
//! - Vec\<T\>
|
||||||
//! - EnumSet\<T\> (unstable)
|
|
||||||
//! - **Zero-copy types**:
|
//! - **Zero-copy types**:
|
||||||
//! - &str
|
//! - &str
|
||||||
//! - &[u8]
|
//! - &[u8]
|
||||||
@@ -98,7 +97,6 @@
|
|||||||
//! - Path
|
//! - Path
|
||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - NonZero\<T\> (unstable, deprecated)
|
|
||||||
//! - num::NonZero* (unstable)
|
//! - num::NonZero* (unstable)
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
//! - IpAddr
|
//! - IpAddr
|
||||||
@@ -1132,18 +1130,6 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
fn is_human_readable(&self) -> bool {
|
fn is_human_readable(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not public API.
|
|
||||||
#[doc(hidden)]
|
|
||||||
fn private_deserialize_internally_tagged_enum<V>(
|
|
||||||
self,
|
|
||||||
visitor: V,
|
|
||||||
) -> Result<V::Value, Self::Error>
|
|
||||||
where
|
|
||||||
V: Visitor<'de>,
|
|
||||||
{
|
|
||||||
self.deserialize_any(visitor)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -1541,6 +1527,15 @@ pub trait Visitor<'de>: Sized {
|
|||||||
let _ = data;
|
let _ = data;
|
||||||
Err(Error::invalid_type(Unexpected::Enum, &self))
|
Err(Error::invalid_type(Unexpected::Enum, &self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used when deserializing a flattened Option field. Not public API.
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn __private_visit_untagged_option<D>(self, _: D) -> Result<Self::Value, ()>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+2
-6
@@ -79,14 +79,14 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 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.52")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.57")]
|
||||||
// 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
|
||||||
// discussion of these features please refer to this issue:
|
// discussion of these features please refer to this issue:
|
||||||
//
|
//
|
||||||
// https://github.com/serde-rs/serde/issues/812
|
// https://github.com/serde-rs/serde/issues/812
|
||||||
#![cfg_attr(feature = "unstable", feature(nonzero, specialization))]
|
#![cfg_attr(feature = "unstable", feature(specialization))]
|
||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
@@ -213,10 +213,6 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[allow(deprecated)]
|
|
||||||
pub use core::nonzero::{NonZero, Zeroable};
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
pub use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
|
pub use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-17
@@ -276,6 +276,8 @@ mod content {
|
|||||||
match *self {
|
match *self {
|
||||||
Content::Str(x) => Some(x),
|
Content::Str(x) => Some(x),
|
||||||
Content::String(ref x) => Some(x),
|
Content::String(ref x) => Some(x),
|
||||||
|
Content::Bytes(x) => str::from_utf8(x).ok(),
|
||||||
|
Content::ByteBuf(ref x) => str::from_utf8(x).ok(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1423,6 +1425,8 @@ mod content {
|
|||||||
match self.content {
|
match self.content {
|
||||||
Content::String(v) => visitor.visit_string(v),
|
Content::String(v) => visitor.visit_string(v),
|
||||||
Content::Str(v) => visitor.visit_borrowed_str(v),
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
Content::ByteBuf(v) => visitor.visit_byte_buf(v),
|
||||||
|
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
|
||||||
_ => Err(self.invalid_type(&visitor)),
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2123,6 +2127,8 @@ mod content {
|
|||||||
match *self.content {
|
match *self.content {
|
||||||
Content::String(ref v) => visitor.visit_str(v),
|
Content::String(ref v) => visitor.visit_str(v),
|
||||||
Content::Str(v) => visitor.visit_borrowed_str(v),
|
Content::Str(v) => visitor.visit_borrowed_str(v),
|
||||||
|
Content::ByteBuf(ref v) => visitor.visit_bytes(v),
|
||||||
|
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
|
||||||
_ => Err(self.invalid_type(&visitor)),
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2640,6 +2646,30 @@ pub struct FlatMapDeserializer<'a, 'de: 'a, E>(
|
|||||||
pub PhantomData<E>,
|
pub PhantomData<E>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
fn deserialize_other<V>() -> Result<V, E> {
|
||||||
|
Err(Error::custom("can only flatten structs and maps"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
macro_rules! forward_to_deserialize_other {
|
||||||
|
($($func:ident ( $($arg:ty),* ))*) => {
|
||||||
|
$(
|
||||||
|
fn $func<V>(self, $(_: $arg,)* _visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
Self::deserialize_other()
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
|
impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
|
||||||
where
|
where
|
||||||
@@ -2647,11 +2677,15 @@ where
|
|||||||
{
|
{
|
||||||
type Error = E;
|
type Error = E;
|
||||||
|
|
||||||
fn deserialize_any<V>(self, _: V) -> Result<V::Value, Self::Error>
|
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
Err(Error::custom("can only flatten structs and maps"))
|
visitor.visit_map(FlatInternallyTaggedAccess {
|
||||||
|
iter: self.0.iter_mut(),
|
||||||
|
pending: None,
|
||||||
|
_marker: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_enum<V>(
|
fn deserialize_enum<V>(
|
||||||
@@ -2710,24 +2744,40 @@ where
|
|||||||
visitor.visit_newtype_struct(self)
|
visitor.visit_newtype_struct(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes
|
|
||||||
byte_buf option unit unit_struct seq tuple tuple_struct identifier
|
|
||||||
ignored_any
|
|
||||||
}
|
|
||||||
|
|
||||||
fn private_deserialize_internally_tagged_enum<V>(
|
|
||||||
self,
|
|
||||||
visitor: V,
|
|
||||||
) -> Result<V::Value, Self::Error>
|
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
visitor.visit_map(FlatInternallyTaggedAccess {
|
match visitor.__private_visit_untagged_option(self) {
|
||||||
iter: self.0.iter_mut(),
|
Ok(value) => Ok(value),
|
||||||
pending: None,
|
Err(()) => Self::deserialize_other(),
|
||||||
_marker: PhantomData,
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
forward_to_deserialize_other! {
|
||||||
|
deserialize_bool()
|
||||||
|
deserialize_i8()
|
||||||
|
deserialize_i16()
|
||||||
|
deserialize_i32()
|
||||||
|
deserialize_i64()
|
||||||
|
deserialize_u8()
|
||||||
|
deserialize_u16()
|
||||||
|
deserialize_u32()
|
||||||
|
deserialize_u64()
|
||||||
|
deserialize_f32()
|
||||||
|
deserialize_f64()
|
||||||
|
deserialize_char()
|
||||||
|
deserialize_str()
|
||||||
|
deserialize_string()
|
||||||
|
deserialize_bytes()
|
||||||
|
deserialize_byte_buf()
|
||||||
|
deserialize_unit()
|
||||||
|
deserialize_unit_struct(&'static str)
|
||||||
|
deserialize_seq()
|
||||||
|
deserialize_tuple(usize)
|
||||||
|
deserialize_tuple_struct(&'static str, usize)
|
||||||
|
deserialize_identifier()
|
||||||
|
deserialize_ignored_any()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1122,14 +1122,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
||||||
Err(self.bad_type(Unsupported::Optional))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_some<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
|
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
Err(self.bad_type(Unsupported::Optional))
|
value.serialize(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||||
|
|||||||
@@ -408,20 +408,6 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<T> Serialize for NonZero<T>
|
|
||||||
where
|
|
||||||
T: Serialize + Zeroable + Clone,
|
|
||||||
{
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
self.clone().get().serialize(serializer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
( $( $T: ident, )+ ) => {
|
( $( $T: ident, )+ ) => {
|
||||||
$(
|
$(
|
||||||
|
|||||||
@@ -81,7 +81,6 @@
|
|||||||
//! - LinkedList\<T\>
|
//! - LinkedList\<T\>
|
||||||
//! - VecDeque\<T\>
|
//! - VecDeque\<T\>
|
||||||
//! - Vec\<T\>
|
//! - Vec\<T\>
|
||||||
//! - EnumSet\<T\> (unstable)
|
|
||||||
//! - **FFI types**:
|
//! - **FFI types**:
|
||||||
//! - CStr
|
//! - CStr
|
||||||
//! - CString
|
//! - CString
|
||||||
@@ -93,7 +92,6 @@
|
|||||||
//! - Path
|
//! - Path
|
||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - NonZero\<T\> (unstable, deprecated)
|
|
||||||
//! - num::NonZero* (unstable)
|
//! - num::NonZero* (unstable)
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
//! - IpAddr
|
//! - IpAddr
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.52" # remember to update html_root_url
|
version = "1.0.57" # 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)]"
|
||||||
|
|||||||
@@ -864,7 +864,9 @@ fn deserialize_struct(
|
|||||||
None => format!("struct {}", params.type_name()),
|
None => format!("struct {}", params.type_name()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let visit_seq = Stmts(deserialize_seq(&type_path, params, fields, true, cattrs, &expecting));
|
let visit_seq = Stmts(deserialize_seq(
|
||||||
|
&type_path, params, fields, true, cattrs, &expecting,
|
||||||
|
));
|
||||||
|
|
||||||
let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() {
|
let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() {
|
||||||
deserialize_struct_as_map_visitor(&type_path, params, fields, cattrs)
|
deserialize_struct_as_map_visitor(&type_path, params, fields, cattrs)
|
||||||
@@ -1263,7 +1265,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
|
|
||||||
#variants_stmt
|
#variants_stmt
|
||||||
|
|
||||||
let __tagged = try!(_serde::Deserializer::private_deserialize_internally_tagged_enum(
|
let __tagged = try!(_serde::Deserializer::deserialize_any(
|
||||||
__deserializer,
|
__deserializer,
|
||||||
_serde::private::de::TaggedContentVisitor::<__Field>::new(#tag)));
|
_serde::private::de::TaggedContentVisitor::<__Field>::new(#tag)));
|
||||||
|
|
||||||
|
|||||||
@@ -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.52")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.57")]
|
||||||
#![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(
|
#![cfg_attr(
|
||||||
|
|||||||
@@ -256,7 +256,10 @@ fn serialize_tuple_struct(
|
|||||||
.map(|(i, field)| match field.attrs.skip_serializing_if() {
|
.map(|(i, field)| match field.attrs.skip_serializing_if() {
|
||||||
None => quote!(1),
|
None => quote!(1),
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
let index = syn::Index { index: i as u32, span: Span::call_site() };
|
let index = syn::Index {
|
||||||
|
index: i as u32,
|
||||||
|
span: Span::call_site(),
|
||||||
|
};
|
||||||
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.52" # remember to update html_root_url
|
version = "1.0.57" # 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"
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.52")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.57")]
|
||||||
#![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))]
|
||||||
|
|||||||
@@ -2062,3 +2062,117 @@ fn test_untagged_enum_containing_flatten() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_flatten_untagged_enum() {
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
struct Outer {
|
||||||
|
#[serde(flatten)]
|
||||||
|
inner: Inner,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum Inner {
|
||||||
|
Variant {
|
||||||
|
a: i32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = Outer {
|
||||||
|
inner: Inner::Variant {
|
||||||
|
a: 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&data,
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::I32(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_flatten_option() {
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
struct Outer {
|
||||||
|
#[serde(flatten)]
|
||||||
|
inner1: Option<Inner1>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
inner2: Option<Inner2>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
struct Inner1 {
|
||||||
|
inner1: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
struct Inner2 {
|
||||||
|
inner2: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Outer {
|
||||||
|
inner1: Some(Inner1 {
|
||||||
|
inner1: 1,
|
||||||
|
}),
|
||||||
|
inner2: Some(Inner2 {
|
||||||
|
inner2: 2,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("inner1"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::Str("inner2"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Outer {
|
||||||
|
inner1: Some(Inner1 {
|
||||||
|
inner1: 1,
|
||||||
|
}),
|
||||||
|
inner2: None,
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("inner1"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Outer {
|
||||||
|
inner1: None,
|
||||||
|
inner2: Some(Inner2 {
|
||||||
|
inner2: 2,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("inner2"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Outer {
|
||||||
|
inner1: None,
|
||||||
|
inner2: None,
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ else
|
|||||||
channel build
|
channel build
|
||||||
cd "$DIR/test_suite"
|
cd "$DIR/test_suite"
|
||||||
channel test --features unstable
|
channel test --features unstable
|
||||||
channel build --tests --features proc-macro2/nightly
|
# Broken while syn and quote update to the new proc-macro API
|
||||||
|
#channel build --tests --features proc-macro2/nightly
|
||||||
if [ -z "${APPVEYOR}" ]; then
|
if [ -z "${APPVEYOR}" ]; then
|
||||||
cd "$DIR/test_suite/no_std"
|
cd "$DIR/test_suite/no_std"
|
||||||
channel build
|
channel build
|
||||||
|
|||||||
Reference in New Issue
Block a user