mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-26 07:27:56 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2db2b53bbf | |||
| d5ec3efe49 | |||
| 71fc318474 | |||
| 5ee2fc0562 | |||
| ca53daf697 | |||
| c3b9ee314b | |||
| dbaf2893e3 | |||
| 34a7108b73 | |||
| db2bafd3f3 |
+1
-6
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.63" # remember to update html_root_url
|
version = "1.0.65" # 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"
|
||||||
@@ -23,11 +23,6 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
# Temporary cfg to work around docs.rs using an old 1.26-dev compiler.
|
|
||||||
rustc-args = ["--cfg", "serde_docs_rs"]
|
|
||||||
rustdoc-args = ["--cfg", "serde_docs_rs"]
|
|
||||||
|
|
||||||
|
|
||||||
### FEATURES #################################################################
|
### FEATURES #################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ fn rustc_minor_version() -> Option<u32> {
|
|||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Temporary workaround to support the old 1.26-dev compiler on docs.rs.
|
||||||
|
if version.contains("0eb87c9bf") {
|
||||||
|
return Some(25);
|
||||||
|
}
|
||||||
|
|
||||||
let mut pieces = version.split('.');
|
let mut pieces = version.split('.');
|
||||||
if pieces.next() != Some("rustc 1") {
|
if pieces.next() != Some("rustc 1") {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
/// ($($tt:tt)*) => {};
|
/// ($($tt:tt)*) => {};
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(all(integer128, not(serde_docs_rs)))]
|
#[cfg(integer128)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! serde_if_integer128 {
|
macro_rules! serde_if_integer128 {
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
@@ -78,7 +78,7 @@ macro_rules! serde_if_integer128 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(not(integer128), serde_docs_rs))]
|
#[cfg(not(integer128))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
macro_rules! serde_if_integer128 {
|
macro_rules! serde_if_integer128 {
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,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.63")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.65")]
|
||||||
// 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
|
||||||
|
|||||||
+61
-15
@@ -2723,7 +2723,7 @@ where
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
visitor.visit_map(FlatMapAccess::new(self.0.iter_mut(), None))
|
visitor.visit_map(FlatMapAccess::new(self.0.iter()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct<V>(
|
fn deserialize_struct<V>(
|
||||||
@@ -2735,7 +2735,7 @@ where
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
visitor.visit_map(FlatMapAccess::new(self.0.iter_mut(), Some(fields)))
|
visitor.visit_map(FlatStructAccess::new(self.0.iter_mut(), fields))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
@@ -2784,22 +2784,19 @@ where
|
|||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub struct FlatMapAccess<'a, 'de: 'a, E> {
|
pub struct FlatMapAccess<'a, 'de: 'a, E> {
|
||||||
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
iter: slice::Iter<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||||
pending_content: Option<Content<'de>>,
|
pending_content: Option<&'a Content<'de>>,
|
||||||
fields: Option<&'static [&'static str]>,
|
|
||||||
_marker: PhantomData<E>,
|
_marker: PhantomData<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
impl<'a, 'de, E> FlatMapAccess<'a, 'de, E> {
|
impl<'a, 'de, E> FlatMapAccess<'a, 'de, E> {
|
||||||
fn new(
|
fn new(
|
||||||
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
iter: slice::Iter<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||||
fields: Option<&'static [&'static str]>,
|
|
||||||
) -> FlatMapAccess<'a, 'de, E> {
|
) -> FlatMapAccess<'a, 'de, E> {
|
||||||
FlatMapAccess {
|
FlatMapAccess {
|
||||||
iter: iter,
|
iter: iter,
|
||||||
pending_content: None,
|
pending_content: None,
|
||||||
fields: fields,
|
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2812,6 +2809,61 @@ where
|
|||||||
{
|
{
|
||||||
type Error = E;
|
type Error = E;
|
||||||
|
|
||||||
|
fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
|
where
|
||||||
|
T: DeserializeSeed<'de>,
|
||||||
|
{
|
||||||
|
while let Some(item) = self.iter.next() {
|
||||||
|
// Items in the vector are nulled out when used by a struct.
|
||||||
|
if let Some((ref key, ref content)) = *item {
|
||||||
|
self.pending_content = Some(content);
|
||||||
|
return seed.deserialize(ContentRefDeserializer::new(key)).map(Some);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||||
|
where
|
||||||
|
T: DeserializeSeed<'de>,
|
||||||
|
{
|
||||||
|
match self.pending_content.take() {
|
||||||
|
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||||
|
None => Err(Error::custom("value is missing")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
pub struct FlatStructAccess<'a, 'de: 'a, E> {
|
||||||
|
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||||
|
pending_content: Option<Content<'de>>,
|
||||||
|
fields: &'static [&'static str],
|
||||||
|
_marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
impl<'a, 'de, E> FlatStructAccess<'a, 'de, E> {
|
||||||
|
fn new(
|
||||||
|
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||||
|
fields: &'static [&'static str],
|
||||||
|
) -> FlatStructAccess<'a, 'de, E> {
|
||||||
|
FlatStructAccess {
|
||||||
|
iter: iter,
|
||||||
|
pending_content: None,
|
||||||
|
fields: fields,
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
where
|
where
|
||||||
T: DeserializeSeed<'de>,
|
T: DeserializeSeed<'de>,
|
||||||
@@ -2822,13 +2874,7 @@ where
|
|||||||
// about. In case we do not know which fields we want, we take them all.
|
// about. In case we do not know which fields we want, we take them all.
|
||||||
let use_item = match *item {
|
let use_item = match *item {
|
||||||
None => false,
|
None => false,
|
||||||
Some((ref c, _)) => c.as_str().map_or(self.fields.is_none(), |key| {
|
Some((ref c, _)) => c.as_str().map_or(false, |key| self.fields.contains(&key)),
|
||||||
match self.fields {
|
|
||||||
None => true,
|
|
||||||
Some(fields) if fields.contains(&key) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if use_item {
|
if use_item {
|
||||||
|
|||||||
@@ -8,10 +8,7 @@
|
|||||||
|
|
||||||
use lib::*;
|
use lib::*;
|
||||||
|
|
||||||
use ser::{Serialize, SerializeTuple, Serializer};
|
use ser::{Error, Serialize, SerializeTuple, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
use ser::Error;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -459,7 +456,10 @@ where
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
self.borrow().serialize(serializer)
|
match self.try_borrow() {
|
||||||
|
Ok(value) => value.serialize(serializer),
|
||||||
|
Err(_) => Err(S::Error::custom("already mutably borrowed")),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.63" # remember to update html_root_url
|
version = "1.0.65" # 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.63")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.65")]
|
||||||
#![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(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.63" # remember to update html_root_url
|
version = "1.0.65" # 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.63")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.65")]
|
||||||
#![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))]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ extern crate serde_derive;
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
use self::serde::de::{self, Unexpected};
|
use self::serde::de::{self, Unexpected};
|
||||||
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use std::collections::HashMap;
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
extern crate serde_test;
|
extern crate serde_test;
|
||||||
@@ -1683,6 +1683,49 @@ fn test_complex_flatten() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_flatten_map_twice() {
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
struct Outer {
|
||||||
|
#[serde(flatten)]
|
||||||
|
first: BTreeMap<String, String>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
between: Inner,
|
||||||
|
#[serde(flatten)]
|
||||||
|
second: BTreeMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
struct Inner {
|
||||||
|
y: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Outer {
|
||||||
|
first: {
|
||||||
|
let mut first = BTreeMap::new();
|
||||||
|
first.insert("x".to_owned(), "X".to_owned());
|
||||||
|
first.insert("y".to_owned(), "Y".to_owned());
|
||||||
|
first
|
||||||
|
},
|
||||||
|
between: Inner { y: "Y".to_owned() },
|
||||||
|
second: {
|
||||||
|
let mut second = BTreeMap::new();
|
||||||
|
second.insert("x".to_owned(), "X".to_owned());
|
||||||
|
second
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("x"),
|
||||||
|
Token::Str("X"),
|
||||||
|
Token::Str("y"),
|
||||||
|
Token::Str("Y"),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flatten_unsupported_type() {
|
fn test_flatten_unsupported_type() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@@ -563,6 +564,13 @@ fn test_cannot_serialize_paths() {
|
|||||||
assert_ser_tokens_error(&path_buf, &[], "path contains invalid UTF-8 characters");
|
assert_ser_tokens_error(&path_buf, &[], "path contains invalid UTF-8 characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cannot_serialize_mutably_borrowed_ref_cell() {
|
||||||
|
let ref_cell = RefCell::new(42);
|
||||||
|
let _reference = ref_cell.borrow_mut();
|
||||||
|
assert_ser_tokens_error(&ref_cell, &[], "already mutably borrowed");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_enum_skipped() {
|
fn test_enum_skipped() {
|
||||||
assert_ser_tokens_error(
|
assert_ser_tokens_error(
|
||||||
|
|||||||
Reference in New Issue
Block a user