mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 19:37:55 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f58000cb41 | |||
| 01b86d5ce4 | |||
| c80f9238d7 | |||
| 62850bf832 | |||
| 9f114548f4 | |||
| 8890061f82 | |||
| 2c05518810 | |||
| 4aeb0df88f | |||
| 6550231a51 | |||
| ea0012fc5a | |||
| d6b62b9417 | |||
| 2ee347c5a5 | |||
| 4305260174 | |||
| 35aae92b56 | |||
| f3f26796c7 |
@@ -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.53" # remember to update html_root_url
|
version = "1.0.56" # 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -1529,6 +1529,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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+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.53")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.56")]
|
||||||
// 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
|
||||||
|
|||||||
+19
-7
@@ -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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2645,10 +2651,7 @@ impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
|
|||||||
where
|
where
|
||||||
E: Error,
|
E: Error,
|
||||||
{
|
{
|
||||||
fn deserialize_other<V>(self, _: V) -> Result<V::Value, E>
|
fn deserialize_other<V>() -> Result<V, E> {
|
||||||
where
|
|
||||||
V: Visitor<'de>,
|
|
||||||
{
|
|
||||||
Err(Error::custom("can only flatten structs and maps"))
|
Err(Error::custom("can only flatten structs and maps"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2657,11 +2660,11 @@ where
|
|||||||
macro_rules! forward_to_deserialize_other {
|
macro_rules! forward_to_deserialize_other {
|
||||||
($($func:ident ( $($arg:ty),* ))*) => {
|
($($func:ident ( $($arg:ty),* ))*) => {
|
||||||
$(
|
$(
|
||||||
fn $func<V>(self, $(_: $arg,)* visitor: V) -> Result<V::Value, Self::Error>
|
fn $func<V>(self, $(_: $arg,)* _visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
self.deserialize_other(visitor)
|
Self::deserialize_other()
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -2741,6 +2744,16 @@ where
|
|||||||
visitor.visit_newtype_struct(self)
|
visitor.visit_newtype_struct(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
match visitor.__private_visit_untagged_option(self) {
|
||||||
|
Ok(value) => Ok(value),
|
||||||
|
Err(()) => Self::deserialize_other(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
forward_to_deserialize_other! {
|
forward_to_deserialize_other! {
|
||||||
deserialize_bool()
|
deserialize_bool()
|
||||||
deserialize_i8()
|
deserialize_i8()
|
||||||
@@ -2758,7 +2771,6 @@ where
|
|||||||
deserialize_string()
|
deserialize_string()
|
||||||
deserialize_bytes()
|
deserialize_bytes()
|
||||||
deserialize_byte_buf()
|
deserialize_byte_buf()
|
||||||
deserialize_option()
|
|
||||||
deserialize_unit()
|
deserialize_unit()
|
||||||
deserialize_unit_struct(&'static str)
|
deserialize_unit_struct(&'static str)
|
||||||
deserialize_seq()
|
deserialize_seq()
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.53" # remember to update html_root_url
|
version = "1.0.56" # 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)
|
||||||
|
|||||||
@@ -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.53")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.56")]
|
||||||
#![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.53" # remember to update html_root_url
|
version = "1.0.56" # 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.53")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.56")]
|
||||||
#![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))]
|
||||||
|
|||||||
@@ -2095,3 +2095,84 @@ fn test_flatten_untagged_enum() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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