mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-21 19:01:05 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b811588fa0 | |||
| 5fcdf0ff2b | |||
| 650b723da3 | |||
| 97920be33a | |||
| 58bbaa9e80 | |||
| 94f152730c | |||
| 535e3d4372 | |||
| 2ea43c8986 | |||
| 71fe2a5534 | |||
| f3ffcfd61e | |||
| bf27b28554 | |||
| 344602d27e | |||
| 64c483cf80 | |||
| 19091aacc7 | |||
| ef9028d798 | |||
| 1668cd19d3 | |||
| 134f268cee | |||
| c473633676 | |||
| 6a3a82007c | |||
| 1d6ef76cfb | |||
| c8e3959435 | |||
| 796f412a1e | |||
| fa854a2108 | |||
| 3a097ff2d2 | |||
| 8463bfc1e5 | |||
| 7a72b4c624 | |||
| 670c179417 | |||
| 1b1d868837 | |||
| d9704d02bb | |||
| 1349548367 | |||
| 18b1604fc8 | |||
| 0def7da5a8 | |||
| 4bb45c8252 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.85" # remember to update html_root_url
|
version = "1.0.89" # 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"
|
||||||
|
|||||||
@@ -14,6 +14,21 @@ fn main() {
|
|||||||
let target = env::var("TARGET").unwrap();
|
let target = env::var("TARGET").unwrap();
|
||||||
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
||||||
|
|
||||||
|
// std::collections::Bound was stabilized in Rust 1.17
|
||||||
|
// but it was moved to core::ops later in Rust 1.26:
|
||||||
|
// https://doc.rust-lang.org/core/ops/enum.Bound.html
|
||||||
|
if minor >= 26 {
|
||||||
|
println!("cargo:rustc-cfg=ops_bound");
|
||||||
|
} else if minor >= 17 && cfg!(feature = "std") {
|
||||||
|
println!("cargo:rustc-cfg=collections_bound");
|
||||||
|
}
|
||||||
|
|
||||||
|
// core::cmp::Reverse stabilized in Rust 1.19:
|
||||||
|
// https://doc.rust-lang.org/stable/core/cmp/struct.Reverse.html
|
||||||
|
if minor >= 19 {
|
||||||
|
println!("cargo:rustc-cfg=core_reverse");
|
||||||
|
}
|
||||||
|
|
||||||
// CString::into_boxed_c_str stabilized in Rust 1.20:
|
// CString::into_boxed_c_str stabilized in Rust 1.20:
|
||||||
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
|
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
|
||||||
if minor >= 20 {
|
if minor >= 20 {
|
||||||
|
|||||||
@@ -578,6 +578,9 @@ macro_rules! forwarded_impl {
|
|||||||
#[cfg(all(feature = "std", de_boxed_c_str))]
|
#[cfg(all(feature = "std", de_boxed_c_str))]
|
||||||
forwarded_impl!((), Box<CStr>, CString::into_boxed_c_str);
|
forwarded_impl!((), Box<CStr>, CString::into_boxed_c_str);
|
||||||
|
|
||||||
|
#[cfg(core_reverse)]
|
||||||
|
forwarded_impl!((T), Reverse<T>, Reverse);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct OptionVisitor<T> {
|
struct OptionVisitor<T> {
|
||||||
@@ -2269,6 +2272,117 @@ mod range {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(ops_bound, collections_bound))]
|
||||||
|
impl<'de, T> Deserialize<'de> for Bound<T>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
enum Field {
|
||||||
|
Unbounded,
|
||||||
|
Included,
|
||||||
|
Excluded,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Field {
|
||||||
|
#[inline]
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct FieldVisitor;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
|
type Value = Field;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("`Unbounded`, `Included` or `Excluded`")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
0 => Ok(Field::Unbounded),
|
||||||
|
1 => Ok(Field::Included),
|
||||||
|
2 => Ok(Field::Excluded),
|
||||||
|
_ => Err(Error::invalid_value(
|
||||||
|
Unexpected::Unsigned(value as u64),
|
||||||
|
&self,
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
"Unbounded" => Ok(Field::Unbounded),
|
||||||
|
"Included" => Ok(Field::Included),
|
||||||
|
"Excluded" => Ok(Field::Excluded),
|
||||||
|
_ => Err(Error::unknown_variant(value, VARIANTS)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
b"Unbounded" => Ok(Field::Unbounded),
|
||||||
|
b"Included" => Ok(Field::Included),
|
||||||
|
b"Excluded" => Ok(Field::Excluded),
|
||||||
|
_ => match str::from_utf8(value) {
|
||||||
|
Ok(value) => Err(Error::unknown_variant(value, VARIANTS)),
|
||||||
|
Err(_) => {
|
||||||
|
Err(Error::invalid_value(Unexpected::Bytes(value), &self))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BoundVisitor<T>(PhantomData<Bound<T>>);
|
||||||
|
|
||||||
|
impl<'de, T> Visitor<'de> for BoundVisitor<T>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
type Value = Bound<T>;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("enum Bound")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: EnumAccess<'de>,
|
||||||
|
{
|
||||||
|
match try!(data.variant()) {
|
||||||
|
(Field::Unbounded, v) => v.unit_variant().map(|()| Bound::Unbounded),
|
||||||
|
(Field::Included, v) => v.newtype_variant().map(Bound::Included),
|
||||||
|
(Field::Excluded, v) => v.newtype_variant().map(Bound::Excluded),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const VARIANTS: &'static [&'static str] = &["Unbounded", "Included", "Excluded"];
|
||||||
|
|
||||||
|
deserializer.deserialize_enum("Bound", VARIANTS, BoundVisitor(PhantomData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
( $( $T: ident, )+ ) => {
|
( $( $T: ident, )+ ) => {
|
||||||
$(
|
$(
|
||||||
|
|||||||
+3
-2
@@ -59,13 +59,13 @@
|
|||||||
//! - Box\<T\>
|
//! - Box\<T\>
|
||||||
//! - Box\<\[T\]\>
|
//! - Box\<\[T\]\>
|
||||||
//! - Box\<str\>
|
//! - Box\<str\>
|
||||||
//! - Rc\<T\>
|
|
||||||
//! - Arc\<T\>
|
|
||||||
//! - Cow\<'a, T\>
|
//! - Cow\<'a, T\>
|
||||||
//! - Cell\<T\>
|
//! - Cell\<T\>
|
||||||
//! - RefCell\<T\>
|
//! - RefCell\<T\>
|
||||||
//! - Mutex\<T\>
|
//! - Mutex\<T\>
|
||||||
//! - RwLock\<T\>
|
//! - RwLock\<T\>
|
||||||
|
//! - Rc\<T\> *(if* features = ["rc"] *is enabled)*
|
||||||
|
//! - Arc\<T\> *(if* features = ["rc"] *is enabled)*
|
||||||
//! - **Collection types**:
|
//! - **Collection types**:
|
||||||
//! - BTreeMap\<K, V\>
|
//! - BTreeMap\<K, V\>
|
||||||
//! - BTreeSet\<T\>
|
//! - BTreeSet\<T\>
|
||||||
@@ -89,6 +89,7 @@
|
|||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - RangeInclusive\<T\>
|
//! - RangeInclusive\<T\>
|
||||||
|
//! - Bound\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
//! - `!` *(unstable)*
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
|
|||||||
+28
-36
@@ -75,7 +75,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.85")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.89")]
|
||||||
// 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
|
||||||
@@ -86,52 +86,35 @@
|
|||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy and clippy_pedantic lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
cast_lossless,
|
// not available in our oldest supported compiler
|
||||||
const_static_lifetime,
|
const_static_lifetime,
|
||||||
doc_markdown,
|
empty_enum,
|
||||||
linkedlist,
|
|
||||||
needless_pass_by_value,
|
|
||||||
redundant_field_names,
|
redundant_field_names,
|
||||||
type_complexity,
|
// integer and float ser/de requires these sorts of casts
|
||||||
unreadable_literal,
|
|
||||||
zero_prefixed_literal
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
// Ignored clippy_pedantic lints
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(
|
|
||||||
// integer and float ser/de requires these sorts of casts
|
|
||||||
cast_possible_truncation,
|
cast_possible_truncation,
|
||||||
cast_possible_wrap,
|
cast_possible_wrap,
|
||||||
cast_precision_loss,
|
cast_precision_loss,
|
||||||
cast_sign_loss,
|
cast_sign_loss,
|
||||||
// simplifies some macros
|
// things are often more readable this way
|
||||||
invalid_upcast_comparisons,
|
cast_lossless,
|
||||||
// things are often more readable this way
|
|
||||||
decimal_literal_representation,
|
|
||||||
module_name_repetitions,
|
module_name_repetitions,
|
||||||
option_unwrap_used,
|
|
||||||
result_unwrap_used,
|
|
||||||
shadow_reuse,
|
|
||||||
single_match_else,
|
single_match_else,
|
||||||
|
type_complexity,
|
||||||
use_self,
|
use_self,
|
||||||
// not practical
|
zero_prefixed_literal,
|
||||||
indexing_slicing,
|
// not practical
|
||||||
many_single_char_names,
|
needless_pass_by_value,
|
||||||
missing_docs_in_private_items,
|
|
||||||
similar_names,
|
similar_names,
|
||||||
// alternative is not stable
|
// preference
|
||||||
empty_enum,
|
doc_markdown,
|
||||||
use_debug,
|
)
|
||||||
))]
|
)]
|
||||||
// Blacklisted Rust lints.
|
// Rustc lints.
|
||||||
//
|
#![deny(missing_docs, unused_imports)]
|
||||||
// Compiler bug involving unused_imports:
|
|
||||||
// https://github.com/rust-lang/rust/issues/51661
|
|
||||||
#![deny(missing_docs, /*unused_imports*/)]
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -219,11 +202,20 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{SystemTime, UNIX_EPOCH};
|
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(any(core_duration, feature = "std"))]
|
#[cfg(all(feature = "std", collections_bound))]
|
||||||
pub use self::core::time::Duration;
|
pub use std::collections::Bound;
|
||||||
|
|
||||||
|
#[cfg(core_reverse)]
|
||||||
|
pub use self::core::cmp::Reverse;
|
||||||
|
|
||||||
|
#[cfg(ops_bound)]
|
||||||
|
pub use self::core::ops::Bound;
|
||||||
|
|
||||||
#[cfg(range_inclusive)]
|
#[cfg(range_inclusive)]
|
||||||
pub use self::core::ops::RangeInclusive;
|
pub use self::core::ops::RangeInclusive;
|
||||||
|
|
||||||
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
|
pub use self::core::time::Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -2709,7 +2709,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
Err(Error::custom(format_args!(
|
Err(Error::custom(format_args!(
|
||||||
"no variant of enum {} not found in flattened data",
|
"no variant of enum {} found in flattened data",
|
||||||
name
|
name
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-2
@@ -160,10 +160,12 @@ macro_rules! array_impls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
array_impls!(01 02 03 04 05 06 07 08 09 10
|
array_impls! {
|
||||||
|
01 02 03 04 05 06 07 08 09 10
|
||||||
11 12 13 14 15 16 17 18 19 20
|
11 12 13 14 15 16 17 18 19 20
|
||||||
21 22 23 24 25 26 27 28 29 30
|
21 22 23 24 25 26 27 28 29 30
|
||||||
31 32);
|
31 32
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -256,6 +258,29 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(ops_bound, collections_bound))]
|
||||||
|
impl<T> Serialize for Bound<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match *self {
|
||||||
|
Bound::Unbounded => serializer.serialize_unit_variant("Bound", 0, "Unbounded"),
|
||||||
|
Bound::Included(ref value) => {
|
||||||
|
serializer.serialize_newtype_variant("Bound", 1, "Included", value)
|
||||||
|
}
|
||||||
|
Bound::Excluded(ref value) => {
|
||||||
|
serializer.serialize_newtype_variant("Bound", 2, "Excluded", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
impl Serialize for () {
|
impl Serialize for () {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -799,3 +824,17 @@ where
|
|||||||
self.0.serialize(serializer)
|
self.0.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(core_reverse)]
|
||||||
|
impl<T> Serialize for Reverse<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
self.0.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,13 +56,13 @@
|
|||||||
//! - PhantomData\<T\>
|
//! - PhantomData\<T\>
|
||||||
//! - **Wrapper types**:
|
//! - **Wrapper types**:
|
||||||
//! - Box\<T\>
|
//! - Box\<T\>
|
||||||
//! - Rc\<T\>
|
|
||||||
//! - Arc\<T\>
|
|
||||||
//! - Cow\<'a, T\>
|
//! - Cow\<'a, T\>
|
||||||
//! - Cell\<T\>
|
//! - Cell\<T\>
|
||||||
//! - RefCell\<T\>
|
//! - RefCell\<T\>
|
||||||
//! - Mutex\<T\>
|
//! - Mutex\<T\>
|
||||||
//! - RwLock\<T\>
|
//! - RwLock\<T\>
|
||||||
|
//! - Rc\<T\> *(if* features = ["rc"] *is enabled)*
|
||||||
|
//! - Arc\<T\> *(if* features = ["rc"] *is enabled)*
|
||||||
//! - **Collection types**:
|
//! - **Collection types**:
|
||||||
//! - BTreeMap\<K, V\>
|
//! - BTreeMap\<K, V\>
|
||||||
//! - BTreeSet\<T\>
|
//! - BTreeSet\<T\>
|
||||||
@@ -84,6 +84,7 @@
|
|||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
//! - RangeInclusive\<T\>
|
//! - RangeInclusive\<T\>
|
||||||
|
//! - Bound\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
//! - `!` *(unstable)*
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.85" # remember to update html_root_url
|
version = "1.0.89" # 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)]"
|
||||||
|
|||||||
+36
-8
@@ -1149,7 +1149,11 @@ fn prepare_enum_variant_enum(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||||
.map(|(i, variant)| {
|
.map(|(i, variant)| {
|
||||||
(variant.attrs.name().deserialize_name(), field_i(i), variant.attrs.aliases())
|
(
|
||||||
|
variant.attrs.name().deserialize_name(),
|
||||||
|
field_i(i),
|
||||||
|
variant.attrs.aliases(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -2275,7 +2279,11 @@ fn deserialize_struct_as_struct_visitor(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| {
|
||||||
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
(
|
||||||
|
field.attrs.name().deserialize_name(),
|
||||||
|
field_i(i),
|
||||||
|
field.attrs.aliases(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -2304,7 +2312,11 @@ fn deserialize_struct_as_map_visitor(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| {
|
||||||
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
(
|
||||||
|
field.attrs.name().deserialize_name(),
|
||||||
|
field_i(i),
|
||||||
|
field.attrs.aliases(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -2372,7 +2384,12 @@ fn deserialize_map(
|
|||||||
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
|
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
|
||||||
quote!({
|
quote!({
|
||||||
#wrapper
|
#wrapper
|
||||||
try!(_serde::de::MapAccess::next_value::<#wrapper_ty>(&mut __map)).value
|
match _serde::de::MapAccess::next_value::<#wrapper_ty>(&mut __map) {
|
||||||
|
_serde::export::Ok(__wrapper) => __wrapper.value,
|
||||||
|
_serde::export::Err(__err) => {
|
||||||
|
return _serde::export::Err(__err);
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2439,7 +2456,7 @@ fn deserialize_map(
|
|||||||
|
|
||||||
let extract_collected = fields_names
|
let extract_collected = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| field.attrs.flatten())
|
.filter(|&&(field, _)| field.attrs.flatten() && !field.attrs.skip_deserializing())
|
||||||
.map(|&(field, ref name)| {
|
.map(|&(field, ref name)| {
|
||||||
let field_ty = field.ty;
|
let field_ty = field.ty;
|
||||||
let func = match field.attrs.deserialize_with() {
|
let func = match field.attrs.deserialize_with() {
|
||||||
@@ -2459,7 +2476,9 @@ fn deserialize_map(
|
|||||||
|
|
||||||
let collected_deny_unknown_fields = if cattrs.has_flatten() && cattrs.deny_unknown_fields() {
|
let collected_deny_unknown_fields = if cattrs.has_flatten() && cattrs.deny_unknown_fields() {
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
if let _serde::export::Some(_serde::export::Some((__key, _))) = __collect.into_iter().filter(|x| x.is_some()).next() {
|
if let _serde::export::Some(_serde::export::Some((__key, _))) =
|
||||||
|
__collect.into_iter().filter(_serde::export::Option::is_some).next()
|
||||||
|
{
|
||||||
if let _serde::export::Some(__key) = __key.as_str() {
|
if let _serde::export::Some(__key) = __key.as_str() {
|
||||||
return _serde::export::Err(
|
return _serde::export::Err(
|
||||||
_serde::de::Error::custom(format_args!("unknown field `{}`", &__key)));
|
_serde::de::Error::custom(format_args!("unknown field `{}`", &__key)));
|
||||||
@@ -2537,7 +2556,11 @@ fn deserialize_struct_as_struct_in_place_visitor(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| {
|
||||||
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
(
|
||||||
|
field.attrs.name().deserialize_name(),
|
||||||
|
field_i(i),
|
||||||
|
field.attrs.aliases(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -2599,7 +2622,12 @@ fn deserialize_map_in_place(
|
|||||||
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
|
let (wrapper, wrapper_ty) = wrap_deserialize_field_with(params, field.ty, path);
|
||||||
quote!({
|
quote!({
|
||||||
#wrapper
|
#wrapper
|
||||||
self.place.#member = try!(_serde::de::MapAccess::next_value::<#wrapper_ty>(&mut __map)).value
|
self.place.#member = match _serde::de::MapAccess::next_value::<#wrapper_ty>(&mut __map) {
|
||||||
|
_serde::export::Ok(__wrapper) => __wrapper.value,
|
||||||
|
_serde::export::Err(__err) => {
|
||||||
|
return _serde::export::Err(__err);
|
||||||
|
}
|
||||||
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -116,8 +116,10 @@ impl<'c, T> VecAttr<'c, T> {
|
|||||||
fn at_most_one(mut self) -> Result<Option<T>, ()> {
|
fn at_most_one(mut self) -> Result<Option<T>, ()> {
|
||||||
if self.values.len() > 1 {
|
if self.values.len() > 1 {
|
||||||
let dup_token = self.first_dup_tokens;
|
let dup_token = self.first_dup_tokens;
|
||||||
self.cx
|
self.cx.error_spanned_by(
|
||||||
.error_spanned_by(dup_token, format!("duplicate serde attribute `{}`", self.name));
|
dup_token,
|
||||||
|
format!("duplicate serde attribute `{}`", self.name),
|
||||||
|
);
|
||||||
Err(())
|
Err(())
|
||||||
} else {
|
} else {
|
||||||
Ok(self.values.pop())
|
Ok(self.values.pop())
|
||||||
|
|||||||
@@ -76,25 +76,6 @@ fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
|||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if field.attrs.skip_serializing() {
|
|
||||||
cx.error_spanned_by(
|
|
||||||
field.original,
|
|
||||||
"#[serde(flatten)] can not be combined with \
|
|
||||||
#[serde(skip_serializing)]",
|
|
||||||
);
|
|
||||||
} else if field.attrs.skip_serializing_if().is_some() {
|
|
||||||
cx.error_spanned_by(
|
|
||||||
field.original,
|
|
||||||
"#[serde(flatten)] can not be combined with \
|
|
||||||
#[serde(skip_serializing_if = \"...\")]",
|
|
||||||
);
|
|
||||||
} else if field.attrs.skip_deserializing() {
|
|
||||||
cx.error_spanned_by(
|
|
||||||
field.original,
|
|
||||||
"#[serde(flatten)] can not be combined with \
|
|
||||||
#[serde(skip_deserializing)]",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `other` attribute must be used at most once and it must be the last
|
/// The `other` attribute must be used at most once and it must be the last
|
||||||
|
|||||||
@@ -13,7 +13,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.85")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.89")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
+28
-19
@@ -289,37 +289,38 @@ fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Contai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_struct_tag_field(cattrs: &attr::Container, struct_trait: &StructTrait) -> TokenStream {
|
||||||
|
match *cattrs.tag() {
|
||||||
|
attr::TagType::Internal { ref tag } => {
|
||||||
|
let type_name = cattrs.name().serialize_name();
|
||||||
|
let func = struct_trait.serialize_field(Span::call_site());
|
||||||
|
quote! {
|
||||||
|
try!(#func(&mut __serde_state, #tag, #type_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => quote! {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn serialize_struct_as_struct(
|
fn serialize_struct_as_struct(
|
||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let mut serialize_fields =
|
let serialize_fields =
|
||||||
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeStruct);
|
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeStruct);
|
||||||
|
|
||||||
let type_name = cattrs.name().serialize_name();
|
let type_name = cattrs.name().serialize_name();
|
||||||
|
|
||||||
let additional_field_count: usize = match *cattrs.tag() {
|
let tag_field = serialize_struct_tag_field(cattrs, &StructTrait::SerializeStruct);
|
||||||
attr::TagType::Internal { ref tag } => {
|
let tag_field_exists = !tag_field.is_empty();
|
||||||
let func = StructTrait::SerializeStruct.serialize_field(Span::call_site());
|
|
||||||
serialize_fields.insert(
|
|
||||||
0,
|
|
||||||
quote! {
|
|
||||||
try!(#func(&mut __serde_state, #tag, #type_name));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
1
|
|
||||||
}
|
|
||||||
_ => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut serialized_fields = fields
|
let mut serialized_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&field| !field.attrs.skip_serializing())
|
.filter(|&field| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some() || additional_field_count > 0);
|
let let_mut = mut_if(serialized_fields.peek().is_some() || tag_field_exists);
|
||||||
|
|
||||||
let len = serialized_fields
|
let len = serialized_fields
|
||||||
.map(|field| match field.attrs.skip_serializing_if() {
|
.map(|field| match field.attrs.skip_serializing_if() {
|
||||||
@@ -330,12 +331,13 @@ fn serialize_struct_as_struct(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fold(
|
.fold(
|
||||||
quote!(#additional_field_count),
|
quote!(#tag_field_exists as usize),
|
||||||
|sum, expr| quote!(#sum + #expr),
|
|sum, expr| quote!(#sum + #expr),
|
||||||
);
|
);
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
||||||
|
#tag_field
|
||||||
#(#serialize_fields)*
|
#(#serialize_fields)*
|
||||||
_serde::ser::SerializeStruct::end(__serde_state)
|
_serde::ser::SerializeStruct::end(__serde_state)
|
||||||
}
|
}
|
||||||
@@ -349,12 +351,15 @@ fn serialize_struct_as_map(
|
|||||||
let serialize_fields =
|
let serialize_fields =
|
||||||
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeMap);
|
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeMap);
|
||||||
|
|
||||||
|
let tag_field = serialize_struct_tag_field(cattrs, &StructTrait::SerializeMap);
|
||||||
|
let tag_field_exists = !tag_field.is_empty();
|
||||||
|
|
||||||
let mut serialized_fields = fields
|
let mut serialized_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&field| !field.attrs.skip_serializing())
|
.filter(|&field| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some());
|
let let_mut = mut_if(serialized_fields.peek().is_some() || tag_field_exists);
|
||||||
|
|
||||||
let len = if cattrs.has_flatten() {
|
let len = if cattrs.has_flatten() {
|
||||||
quote!(_serde::export::None)
|
quote!(_serde::export::None)
|
||||||
@@ -367,12 +372,16 @@ fn serialize_struct_as_map(
|
|||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
.fold(
|
||||||
|
quote!(#tag_field_exists as usize),
|
||||||
|
|sum, expr| quote!(#sum + #expr),
|
||||||
|
);
|
||||||
quote!(_serde::export::Some(#len))
|
quote!(_serde::export::Some(#len))
|
||||||
};
|
};
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(__serializer, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(__serializer, #len));
|
||||||
|
#tag_field
|
||||||
#(#serialize_fields)*
|
#(#serialize_fields)*
|
||||||
_serde::ser::SerializeMap::end(__serde_state)
|
_serde::ser::SerializeMap::end(__serde_state)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.85" # remember to update html_root_url
|
version = "1.0.89" # 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"
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.85")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.89")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#### To run unit tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
#### To run ui tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
(cd deps && cargo clean && cargo update && cargo build)
|
||||||
|
cargo test --features compiletest
|
||||||
|
```
|
||||||
|
|
||||||
|
#### To update goldens after running ui tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tests/ui/update-references.sh
|
||||||
|
```
|
||||||
@@ -15,6 +15,7 @@ fn ui() {
|
|||||||
--extern serde_derive \
|
--extern serde_derive \
|
||||||
",
|
",
|
||||||
)),
|
)),
|
||||||
|
build_base: std::path::PathBuf::from("../target/ui"),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -574,7 +574,11 @@ fn test_rename_struct() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_de_tokens(
|
assert_de_tokens(
|
||||||
&AliasStruct { a1: 1, a2: 2, a4: 3 },
|
&AliasStruct {
|
||||||
|
a1: 1,
|
||||||
|
a2: 2,
|
||||||
|
a4: 3,
|
||||||
|
},
|
||||||
&[
|
&[
|
||||||
Token::Struct {
|
Token::Struct {
|
||||||
name: "AliasStruct",
|
name: "AliasStruct",
|
||||||
@@ -591,7 +595,11 @@ fn test_rename_struct() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_de_tokens(
|
assert_de_tokens(
|
||||||
&AliasStruct { a1: 1, a2: 2, a4: 3 },
|
&AliasStruct {
|
||||||
|
a1: 1,
|
||||||
|
a2: 2,
|
||||||
|
a4: 3,
|
||||||
|
},
|
||||||
&[
|
&[
|
||||||
Token::Struct {
|
Token::Struct {
|
||||||
name: "AliasStruct",
|
name: "AliasStruct",
|
||||||
@@ -665,7 +673,7 @@ enum AliasEnum {
|
|||||||
b: i8,
|
b: i8,
|
||||||
#[serde(alias = "e", rename = "f")]
|
#[serde(alias = "e", rename = "f")]
|
||||||
d: i8,
|
d: i8,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -756,11 +764,7 @@ fn test_rename_enum() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_de_tokens(
|
assert_de_tokens(
|
||||||
&AliasEnum::SailorMoon {
|
&AliasEnum::SailorMoon { a: 0, b: 1, d: 2 },
|
||||||
a: 0,
|
|
||||||
b: 1,
|
|
||||||
d: 2,
|
|
||||||
},
|
|
||||||
&[
|
&[
|
||||||
Token::StructVariant {
|
Token::StructVariant {
|
||||||
name: "AliasEnum",
|
name: "AliasEnum",
|
||||||
@@ -778,11 +782,7 @@ fn test_rename_enum() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_de_tokens(
|
assert_de_tokens(
|
||||||
&AliasEnum::SailorMoon {
|
&AliasEnum::SailorMoon { a: 0, b: 1, d: 2 },
|
||||||
a: 0,
|
|
||||||
b: 1,
|
|
||||||
d: 2,
|
|
||||||
},
|
|
||||||
&[
|
&[
|
||||||
Token::StructVariant {
|
Token::StructVariant {
|
||||||
name: "AliasEnum",
|
name: "AliasEnum",
|
||||||
@@ -803,13 +803,11 @@ fn test_rename_enum() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_unknown_field_rename_enum() {
|
fn test_unknown_field_rename_enum() {
|
||||||
assert_de_tokens_error::<AliasEnum>(
|
assert_de_tokens_error::<AliasEnum>(
|
||||||
&[
|
&[Token::StructVariant {
|
||||||
Token::StructVariant {
|
|
||||||
name: "AliasEnum",
|
name: "AliasEnum",
|
||||||
variant: "SailorMoon",
|
variant: "SailorMoon",
|
||||||
len: 3,
|
len: 3,
|
||||||
},
|
}],
|
||||||
],
|
|
||||||
"unknown variant `SailorMoon`, expected `sailor_moon`",
|
"unknown variant `SailorMoon`, expected `sailor_moon`",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::default::Default;
|
|||||||
use std::ffi::{CStr, CString, OsString};
|
use std::ffi::{CStr, CString, OsString};
|
||||||
use std::net;
|
use std::net;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
|
use std::ops::Bound;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::{Rc, Weak as RcWeak};
|
use std::rc::{Rc, Weak as RcWeak};
|
||||||
use std::sync::{Arc, Weak as ArcWeak};
|
use std::sync::{Arc, Weak as ArcWeak};
|
||||||
@@ -836,6 +837,23 @@ declare_tests! {
|
|||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_bound {
|
||||||
|
Bound::Unbounded::<()> => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Unbounded"),
|
||||||
|
Token::Unit,
|
||||||
|
],
|
||||||
|
Bound::Included(0) => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Included"),
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
Bound::Excluded(0) => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Excluded"),
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
}
|
||||||
test_path {
|
test_path {
|
||||||
Path::new("/usr/local/lib") => &[
|
Path::new("/usr/local/lib") => &[
|
||||||
Token::BorrowedStr("/usr/local/lib"),
|
Token::BorrowedStr("/usr/local/lib"),
|
||||||
|
|||||||
@@ -522,6 +522,13 @@ fn test_gen() {
|
|||||||
}
|
}
|
||||||
assert::<FlattenWith>();
|
assert::<FlattenWith>();
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct FlattenDenyUnknown<T> {
|
||||||
|
#[serde(flatten)]
|
||||||
|
t: T,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct StaticStrStruct<'a> {
|
struct StaticStrStruct<'a> {
|
||||||
a: &'a str,
|
a: &'a str,
|
||||||
@@ -665,6 +672,25 @@ fn test_gen() {
|
|||||||
ty: &'a str,
|
ty: &'a str,
|
||||||
id: String,
|
id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct FlattenSkipSerializing<T> {
|
||||||
|
#[serde(flatten, skip_serializing)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
flat: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct FlattenSkipSerializingIf<T> {
|
||||||
|
#[serde(flatten, skip_serializing_if = "StdOption::is_none")]
|
||||||
|
flat: StdOption<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct FlattenSkipDeserializing<T> {
|
||||||
|
#[serde(flatten, skip_deserializing)]
|
||||||
|
flat: T,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1424,6 +1424,48 @@ fn test_internally_tagged_braced_struct_with_zero_fields() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_internally_tagged_struct_with_flattened_field() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "tag_struct")]
|
||||||
|
pub struct Struct {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub flat: Enum,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "tag_enum", content = "content")]
|
||||||
|
pub enum Enum {
|
||||||
|
A(u64),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Struct { flat: Enum::A(0) },
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("tag_struct"),
|
||||||
|
Token::Str("Struct"),
|
||||||
|
Token::Str("tag_enum"),
|
||||||
|
Token::Str("A"),
|
||||||
|
Token::Str("content"),
|
||||||
|
Token::U64(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Struct { flat: Enum::A(0) },
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("tag_enum"),
|
||||||
|
Token::Str("A"),
|
||||||
|
Token::Str("content"),
|
||||||
|
Token::U64(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_enum_in_untagged_enum() {
|
fn test_enum_in_untagged_enum() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::ffi::CString;
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::net;
|
use std::net;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
|
use std::ops::Bound;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::{Rc, Weak as RcWeak};
|
use std::rc::{Rc, Weak as RcWeak};
|
||||||
use std::sync::{Arc, Weak as ArcWeak};
|
use std::sync::{Arc, Weak as ArcWeak};
|
||||||
@@ -375,6 +376,23 @@ declare_tests! {
|
|||||||
Token::StructEnd,
|
Token::StructEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_bound {
|
||||||
|
Bound::Unbounded::<()> => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Unbounded"),
|
||||||
|
Token::Unit,
|
||||||
|
],
|
||||||
|
Bound::Included(0u8) => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Included"),
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
Bound::Excluded(0u8) => &[
|
||||||
|
Token::Enum { name: "Bound" },
|
||||||
|
Token::Str("Excluded"),
|
||||||
|
Token::U8(0),
|
||||||
|
],
|
||||||
|
}
|
||||||
test_path {
|
test_path {
|
||||||
Path::new("/usr/local/lib") => &[
|
Path::new("/usr/local/lib") => &[
|
||||||
Token::Str("/usr/local/lib"),
|
Token::Str("/usr/local/lib"),
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
use serde_derive::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Foo {
|
|
||||||
#[serde(flatten, skip_deserializing)]
|
|
||||||
other: Other,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Other {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_deserializing)]
|
|
||||||
--> $DIR/flatten-skip-deserializing.rs:5:5
|
|
||||||
|
|
|
||||||
5 | / #[serde(flatten, skip_deserializing)]
|
|
||||||
6 | | other: Other,
|
|
||||||
| |________________^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
use serde_derive::Serialize;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Foo {
|
|
||||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
|
||||||
other: Option<Other>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Other {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing_if = "...")]
|
|
||||||
--> $DIR/flatten-skip-serializing-if.rs:5:5
|
|
||||||
|
|
|
||||||
5 | / #[serde(flatten, skip_serializing_if = "Option::is_none")]
|
|
||||||
6 | | other: Option<Other>,
|
|
||||||
| |________________________^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
use serde_derive::Serialize;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Foo {
|
|
||||||
#[serde(flatten, skip_serializing)]
|
|
||||||
other: Other,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Other {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing)]
|
|
||||||
--> $DIR/flatten-skip-serializing.rs:5:5
|
|
||||||
|
|
|
||||||
5 | / #[serde(flatten, skip_serializing)]
|
|
||||||
6 | | other: Other,
|
|
||||||
| |________________^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
@@ -19,32 +19,20 @@
|
|||||||
# If you find yourself manually editing a foo.stderr file, you're
|
# If you find yourself manually editing a foo.stderr file, you're
|
||||||
# doing it wrong.
|
# doing it wrong.
|
||||||
|
|
||||||
if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
echo "usage: $0 <build-directory> <relative-path-to-rs-files>"
|
BUILD_DIR="../../../target/ui"
|
||||||
echo ""
|
|
||||||
echo "For example:"
|
|
||||||
echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs"
|
|
||||||
fi
|
|
||||||
|
|
||||||
MYDIR=$(dirname $0)
|
for testcase in */*.rs; do
|
||||||
|
STDERR_NAME="${testcase/%.rs/.stderr}"
|
||||||
BUILD_DIR="$1"
|
STDOUT_NAME="${testcase/%.rs/.stdout}"
|
||||||
shift
|
if [ -f "$BUILD_DIR/$STDOUT_NAME" ] && \
|
||||||
|
! (diff "$BUILD_DIR/$STDOUT_NAME" "$STDOUT_NAME" >& /dev/null); then
|
||||||
while [[ "$1" != "" ]]; do
|
echo "updating $STDOUT_NAME"
|
||||||
STDERR_NAME="${1/%.rs/.stderr}"
|
cp "$BUILD_DIR/$STDOUT_NAME" "$STDOUT_NAME"
|
||||||
STDOUT_NAME="${1/%.rs/.stdout}"
|
|
||||||
shift
|
|
||||||
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
|
|
||||||
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
|
|
||||||
echo updating $MYDIR/$STDOUT_NAME
|
|
||||||
cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME
|
|
||||||
fi
|
fi
|
||||||
if [ -f $BUILD_DIR/$STDERR_NAME ] && \
|
if [ -f "$BUILD_DIR/$STDERR_NAME" ] && \
|
||||||
! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then
|
! (diff "$BUILD_DIR/$STDERR_NAME" "$STDERR_NAME" >& /dev/null); then
|
||||||
echo updating $MYDIR/$STDERR_NAME
|
echo "updating $STDERR_NAME"
|
||||||
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
|
cp "$BUILD_DIR/$STDERR_NAME" "$STDERR_NAME"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user