mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-18 16:41:03 +00:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 033d05f70b | |||
| fe4e3fd3b0 | |||
| 8a8a8a70ee | |||
| 339dca828d | |||
| 0d7349fa4e | |||
| 830528d5b1 | |||
| ab90fbc7c9 | |||
| 3eec111e8f | |||
| 9388433642 | |||
| ba12070665 | |||
| a57a324d72 | |||
| 92e91b3557 | |||
| 4dcf791706 | |||
| e77900fb94 | |||
| 1b14cadf20 | |||
| 4f59cd217a | |||
| 27c8b2d66a | |||
| 89976c2712 | |||
| c91737fef1 | |||
| a100719bc6 | |||
| 9a0e149225 | |||
| 9350927903 | |||
| 677c13a4ec | |||
| ee8e1ee7ff | |||
| f969080b9f | |||
| c2b16bfbb0 | |||
| e7df53701c | |||
| 02c34e490b | |||
| 427c839b3d | |||
| 4e5e55bf1c | |||
| 4513a9e6a7 | |||
| 4f922e4e5b | |||
| 993966600e | |||
| 5b96cf1bde | |||
| f3d50e5209 | |||
| ab21d4d017 | |||
| f7c5d93e6a | |||
| 52a7d40e6e | |||
| 348bc6b257 |
+24
-19
@@ -77,7 +77,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
rust: [1.19.0, 1.20.0, 1.21.0, 1.25.0, 1.26.0, 1.34.0]
|
rust: [1.31.0, 1.34.0]
|
||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -88,24 +88,6 @@ jobs:
|
|||||||
- run: cd serde && cargo build --no-default-features
|
- run: cd serde && cargo build --no-default-features
|
||||||
- run: cd serde && cargo build
|
- run: cd serde && cargo build
|
||||||
|
|
||||||
more:
|
|
||||||
name: Rust ${{matrix.rust}}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
rust: [1.27.0, 1.28.0]
|
|
||||||
timeout-minutes: 45
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: dtolnay/rust-toolchain@master
|
|
||||||
with:
|
|
||||||
toolchain: ${{matrix.rust}}
|
|
||||||
# Work around failing to parse manifest because editions are unstable.
|
|
||||||
- run: sed -i /test_suite/d Cargo.toml
|
|
||||||
- run: cd serde && cargo build --no-default-features
|
|
||||||
- run: cd serde && cargo build
|
|
||||||
|
|
||||||
derive:
|
derive:
|
||||||
name: Rust 1.56.0
|
name: Rust 1.56.0
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -127,6 +109,29 @@ jobs:
|
|||||||
- uses: dtolnay/rust-toolchain@1.36.0
|
- uses: dtolnay/rust-toolchain@1.36.0
|
||||||
- run: cd serde && cargo build --no-default-features --features alloc
|
- run: cd serde && cargo build --no-default-features --features alloc
|
||||||
|
|
||||||
|
precompiled:
|
||||||
|
name: Precompiled
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 45
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: dtolnay/rust-toolchain@nightly
|
||||||
|
with:
|
||||||
|
components: rust-src
|
||||||
|
targets: x86_64-unknown-linux-musl
|
||||||
|
- run: precompiled/build.sh
|
||||||
|
- name: replace serde_derive dependency with precompiled
|
||||||
|
run: |
|
||||||
|
# FIXME: consider using `cargo rm serde_derive` but it's currently broken
|
||||||
|
# https://github.com/rust-lang/cargo/issues/12419
|
||||||
|
sed -i '/serde_derive =/d' serde/Cargo.toml
|
||||||
|
sed -i '/derive = \["serde_derive"\]/d' serde/Cargo.toml
|
||||||
|
sed -i '/"serde_derive"/d' Cargo.toml
|
||||||
|
sed -i '/\[workspace\]/d' precompiled/serde_derive/Cargo.toml
|
||||||
|
cargo add --dev serde_derive --path precompiled/serde_derive --manifest-path test_suite/Cargo.toml
|
||||||
|
git diff
|
||||||
|
- run: cd test_suite && cargo test --features unstable -- --skip ui --exact
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
name: macOS
|
name: macOS
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.19+]][Rust 1.19] [![serde_derive: rustc 1.56+]][Rust 1.56]
|
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.31+]][Rust 1.31] [![serde_derive: rustc 1.56+]][Rust 1.56]
|
||||||
|
|
||||||
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
|
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
|
||||||
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
|
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
|
||||||
[Latest Version]: https://img.shields.io/crates/v/serde.svg
|
[Latest Version]: https://img.shields.io/crates/v/serde.svg
|
||||||
[crates.io]: https://crates.io/crates/serde
|
[crates.io]: https://crates.io/crates/serde
|
||||||
[serde: rustc 1.19+]: https://img.shields.io/badge/serde-rustc_1.19+-lightgray.svg
|
[serde: rustc 1.31+]: https://img.shields.io/badge/serde-rustc_1.31+-lightgray.svg
|
||||||
[serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg
|
[serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg
|
||||||
[Rust 1.19]: https://blog.rust-lang.org/2017/07/20/Rust-1.19.html
|
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
|
||||||
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
|
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
|
||||||
|
|
||||||
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.178"
|
version = "1.0.180"
|
||||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
@@ -14,4 +14,4 @@ path = "main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
quote = { version = "1", default-features = false }
|
quote = { version = "1", default-features = false }
|
||||||
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "full", "parsing", "printing"] }
|
syn = { version = "2.0.28", default-features = false, features = ["clone-impls", "derive", "full", "parsing", "printing"] }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.178"
|
version = "1.0.180"
|
||||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||||
categories = ["no-std", "no-std::no-alloc"]
|
categories = ["no-std", "no-std::no-alloc"]
|
||||||
description = "Implementation of #[derive(Serialize, Deserialize)]"
|
description = "Implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -24,7 +24,7 @@ proc-macro = true
|
|||||||
[target.'cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))'.dependencies]
|
[target.'cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))'.dependencies]
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
quote = "1"
|
quote = "1"
|
||||||
syn = "2.0.25"
|
syn = "2.0.28"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1", path = "../../serde" }
|
serde = { version = "1", path = "../../serde" }
|
||||||
|
|||||||
@@ -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.178")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.180")]
|
||||||
|
|
||||||
#[cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))]
|
#[cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))]
|
||||||
include!("lib_from_source.rs");
|
include!("lib_from_source.rs");
|
||||||
|
|||||||
+4
-3
@@ -1,20 +1,21 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.178" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.180" # remember to update html_root_url and serde_derive dependency
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
documentation = "https://docs.rs/serde"
|
documentation = "https://docs.rs/serde"
|
||||||
|
edition = "2018"
|
||||||
homepage = "https://serde.rs"
|
homepage = "https://serde.rs"
|
||||||
keywords = ["serde", "serialization", "no_std"]
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "crates-io.md"
|
readme = "crates-io.md"
|
||||||
repository = "https://github.com/serde-rs/serde"
|
repository = "https://github.com/serde-rs/serde"
|
||||||
rust-version = "1.19"
|
rust-version = "1.31"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.178", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.180", optional = true, path = "../serde_derive" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1", path = "../serde_derive" }
|
serde_derive = { version = "1", path = "../serde_derive" }
|
||||||
|
|||||||
+7
-62
@@ -16,68 +16,6 @@ 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=no_ops_bound");
|
|
||||||
if minor < 17 {
|
|
||||||
println!("cargo:rustc-cfg=no_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=no_core_reverse");
|
|
||||||
}
|
|
||||||
|
|
||||||
// CString::into_boxed_c_str and PathBuf::into_boxed_path 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/path/struct.PathBuf.html#method.into_boxed_path
|
|
||||||
if minor < 20 {
|
|
||||||
println!("cargo:rustc-cfg=no_de_boxed_c_str");
|
|
||||||
println!("cargo:rustc-cfg=no_de_boxed_path");
|
|
||||||
}
|
|
||||||
|
|
||||||
// From<Box<T>> for Rc<T> / Arc<T> stabilized in Rust 1.21:
|
|
||||||
// https://doc.rust-lang.org/std/rc/struct.Rc.html#impl-From<Box<T>>
|
|
||||||
// https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-From<Box<T>>
|
|
||||||
if minor < 21 {
|
|
||||||
println!("cargo:rustc-cfg=no_de_rc_dst");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Duration available in core since Rust 1.25:
|
|
||||||
// https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#library-stabilizations
|
|
||||||
if minor < 25 {
|
|
||||||
println!("cargo:rustc-cfg=no_core_duration");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 128-bit integers stabilized in Rust 1.26:
|
|
||||||
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
|
|
||||||
//
|
|
||||||
// Disabled on Emscripten targets before Rust 1.40 since
|
|
||||||
// Emscripten did not support 128-bit integers until Rust 1.40
|
|
||||||
// (https://github.com/rust-lang/rust/pull/65251)
|
|
||||||
if minor < 26 || emscripten && minor < 40 {
|
|
||||||
println!("cargo:rustc-cfg=no_integer128");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inclusive ranges methods stabilized in Rust 1.27:
|
|
||||||
// https://github.com/rust-lang/rust/pull/50758
|
|
||||||
// Also Iterator::try_for_each:
|
|
||||||
// https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#library-stabilizations
|
|
||||||
if minor < 27 {
|
|
||||||
println!("cargo:rustc-cfg=no_range_inclusive");
|
|
||||||
println!("cargo:rustc-cfg=no_iterator_try_fold");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Non-zero integers stabilized in Rust 1.28:
|
|
||||||
// https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#library-stabilizations
|
|
||||||
if minor < 28 {
|
|
||||||
println!("cargo:rustc-cfg=no_num_nonzero");
|
|
||||||
}
|
|
||||||
|
|
||||||
// TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add
|
// TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add
|
||||||
// stabilized in Rust 1.34:
|
// stabilized in Rust 1.34:
|
||||||
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
|
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
|
||||||
@@ -89,6 +27,13 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=no_relaxed_trait_bounds");
|
println!("cargo:rustc-cfg=no_relaxed_trait_bounds");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disabled on Emscripten targets before Rust 1.40 since
|
||||||
|
// Emscripten did not support 128-bit integers until Rust 1.40
|
||||||
|
// (https://github.com/rust-lang/rust/pull/65251)
|
||||||
|
if emscripten && minor < 40 {
|
||||||
|
println!("cargo:rustc-cfg=no_integer128");
|
||||||
|
}
|
||||||
|
|
||||||
// Current minimum supported version of serde_derive crate is Rust 1.56.
|
// Current minimum supported version of serde_derive crate is Rust 1.56.
|
||||||
if minor < 56 {
|
if minor < 56 {
|
||||||
println!("cargo:rustc-cfg=no_serde_derive");
|
println!("cargo:rustc-cfg=no_serde_derive");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use lib::fmt::{self, Write};
|
use crate::lib::fmt::{self, Write};
|
||||||
use lib::str;
|
use crate::lib::str;
|
||||||
|
|
||||||
pub(super) struct Buf<'a> {
|
pub(super) struct Buf<'a> {
|
||||||
bytes: &'a mut [u8],
|
bytes: &'a mut [u8],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{
|
use crate::de::{
|
||||||
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, VariantAccess, Visitor,
|
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, VariantAccess, Visitor,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
while let Some(IgnoredAny) = try!(seq.next_element()) {
|
while let Some(IgnoredAny) = tri!(seq.next_element()) {
|
||||||
// Gobble
|
// Gobble
|
||||||
}
|
}
|
||||||
Ok(IgnoredAny)
|
Ok(IgnoredAny)
|
||||||
@@ -208,7 +208,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
|
|||||||
where
|
where
|
||||||
A: MapAccess<'de>,
|
A: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
while let Some((IgnoredAny, IgnoredAny)) = try!(map.next_entry()) {
|
while let Some((IgnoredAny, IgnoredAny)) = tri!(map.next_entry()) {
|
||||||
// Gobble
|
// Gobble
|
||||||
}
|
}
|
||||||
Ok(IgnoredAny)
|
Ok(IgnoredAny)
|
||||||
@@ -227,7 +227,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
|
|||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: EnumAccess<'de>,
|
||||||
{
|
{
|
||||||
try!(data.variant::<IgnoredAny>()).1.newtype_variant()
|
tri!(data.variant::<IgnoredAny>()).1.newtype_variant()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+72
-117
@@ -1,16 +1,14 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{
|
use crate::de::{
|
||||||
Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess, Visitor,
|
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
||||||
|
Visitor,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc", not(no_core_duration)))]
|
use crate::seed::InPlaceSeed;
|
||||||
use de::MapAccess;
|
|
||||||
|
|
||||||
use seed::InPlaceSeed;
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
use __private::size_hint;
|
use crate::__private::size_hint;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ macro_rules! impl_deserialize_num {
|
|||||||
($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {
|
($primitive:ident, $nonzero:ident $(cfg($($cfg:tt)*))*, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {
|
||||||
impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*);
|
impl_deserialize_num!($primitive, $deserialize $($method!($($val : $visit)*);)*);
|
||||||
|
|
||||||
#[cfg(all(not(no_num_nonzero), $($($cfg)*)*))]
|
$(#[cfg($($cfg)*)])*
|
||||||
impl<'de> Deserialize<'de> for num::$nonzero {
|
impl<'de> Deserialize<'de> for num::$nonzero {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -684,7 +682,7 @@ impl<'de> Visitor<'de> for CStringVisitor {
|
|||||||
let capacity = size_hint::cautious::<u8>(seq.size_hint());
|
let capacity = size_hint::cautious::<u8>(seq.size_hint());
|
||||||
let mut values = Vec::<u8>::with_capacity(capacity);
|
let mut values = Vec::<u8>::with_capacity(capacity);
|
||||||
|
|
||||||
while let Some(value) = try!(seq.next_element()) {
|
while let Some(value) = tri!(seq.next_element()) {
|
||||||
values.push(value);
|
values.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,13 +745,9 @@ macro_rules! forwarded_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
|
||||||
any(feature = "std", all(not(no_core_cstr), feature = "alloc")),
|
|
||||||
not(no_de_boxed_c_str)
|
|
||||||
))]
|
|
||||||
forwarded_impl!((), Box<CStr>, CString::into_boxed_c_str);
|
forwarded_impl!((), Box<CStr>, CString::into_boxed_c_str);
|
||||||
|
|
||||||
#[cfg(not(no_core_reverse))]
|
|
||||||
forwarded_impl!((T), Reverse<T>, Reverse);
|
forwarded_impl!((T), Reverse<T>, Reverse);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -901,7 +895,7 @@ macro_rules! seq_impl {
|
|||||||
{
|
{
|
||||||
let mut values = $with_capacity;
|
let mut values = $with_capacity;
|
||||||
|
|
||||||
while let Some(value) = try!($access.next_element()) {
|
while let Some(value) = tri!($access.next_element()) {
|
||||||
$insert(&mut values, value);
|
$insert(&mut values, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -939,7 +933,7 @@ macro_rules! seq_impl {
|
|||||||
$reserve(&mut self.0, size_hint::cautious::<T>($access.size_hint()));
|
$reserve(&mut self.0, size_hint::cautious::<T>($access.size_hint()));
|
||||||
|
|
||||||
// FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList)
|
// FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList)
|
||||||
while let Some(value) = try!($access.next_element()) {
|
while let Some(value) = tri!($access.next_element()) {
|
||||||
$insert(&mut self.0, value);
|
$insert(&mut self.0, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1039,7 +1033,7 @@ where
|
|||||||
let capacity = size_hint::cautious::<T>(seq.size_hint());
|
let capacity = size_hint::cautious::<T>(seq.size_hint());
|
||||||
let mut values = Vec::<T>::with_capacity(capacity);
|
let mut values = Vec::<T>::with_capacity(capacity);
|
||||||
|
|
||||||
while let Some(value) = try!(seq.next_element()) {
|
while let Some(value) = tri!(seq.next_element()) {
|
||||||
values.push(value);
|
values.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1081,7 +1075,7 @@ where
|
|||||||
for i in 0..self.0.len() {
|
for i in 0..self.0.len() {
|
||||||
let next = {
|
let next = {
|
||||||
let next_place = InPlaceSeed(&mut self.0[i]);
|
let next_place = InPlaceSeed(&mut self.0[i]);
|
||||||
try!(seq.next_element_seed(next_place))
|
tri!(seq.next_element_seed(next_place))
|
||||||
};
|
};
|
||||||
if next.is_none() {
|
if next.is_none() {
|
||||||
self.0.truncate(i);
|
self.0.truncate(i);
|
||||||
@@ -1089,7 +1083,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(value) = try!(seq.next_element()) {
|
while let Some(value) = tri!(seq.next_element()) {
|
||||||
self.0.push(value);
|
self.0.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1161,7 +1155,7 @@ macro_rules! array_impls {
|
|||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
Ok([$(
|
Ok([$(
|
||||||
match try!(seq.next_element()) {
|
match tri!(seq.next_element()) {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => return Err(Error::invalid_length($n, &self)),
|
None => return Err(Error::invalid_length($n, &self)),
|
||||||
}
|
}
|
||||||
@@ -1186,7 +1180,7 @@ macro_rules! array_impls {
|
|||||||
{
|
{
|
||||||
let mut fail_idx = None;
|
let mut fail_idx = None;
|
||||||
for (idx, dest) in self.0[..].iter_mut().enumerate() {
|
for (idx, dest) in self.0[..].iter_mut().enumerate() {
|
||||||
if try!(seq.next_element_seed(InPlaceSeed(dest))).is_none() {
|
if tri!(seq.next_element_seed(InPlaceSeed(dest))).is_none() {
|
||||||
fail_idx = Some(idx);
|
fail_idx = Some(idx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1284,7 +1278,7 @@ macro_rules! tuple_impls {
|
|||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
$(
|
$(
|
||||||
let $name = match try!(seq.next_element()) {
|
let $name = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => return Err(Error::invalid_length($n, &self)),
|
None => return Err(Error::invalid_length($n, &self)),
|
||||||
};
|
};
|
||||||
@@ -1318,7 +1312,7 @@ macro_rules! tuple_impls {
|
|||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
$(
|
$(
|
||||||
if try!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
|
if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
|
||||||
return Err(Error::invalid_length($n, &self));
|
return Err(Error::invalid_length($n, &self));
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
@@ -1395,7 +1389,7 @@ macro_rules! map_impl {
|
|||||||
{
|
{
|
||||||
let mut values = $with_capacity;
|
let mut values = $with_capacity;
|
||||||
|
|
||||||
while let Some((key, value)) = try!($access.next_entry()) {
|
while let Some((key, value)) = tri!($access.next_entry()) {
|
||||||
values.insert(key, value);
|
values.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1541,7 +1535,7 @@ macro_rules! deserialize_enum {
|
|||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: EnumAccess<'de>,
|
||||||
{
|
{
|
||||||
match try!(data.variant()) {
|
match tri!(data.variant()) {
|
||||||
$(
|
$(
|
||||||
($name_kind :: $variant, v) => v.newtype_variant().map($name :: $variant),
|
($name_kind :: $variant, v) => v.newtype_variant().map($name :: $variant),
|
||||||
)*
|
)*
|
||||||
@@ -1561,7 +1555,7 @@ impl<'de> Deserialize<'de> for net::IpAddr {
|
|||||||
if deserializer.is_human_readable() {
|
if deserializer.is_human_readable() {
|
||||||
deserializer.deserialize_str(FromStrVisitor::new("IP address"))
|
deserializer.deserialize_str(FromStrVisitor::new("IP address"))
|
||||||
} else {
|
} else {
|
||||||
use lib::net::IpAddr;
|
use crate::lib::net::IpAddr;
|
||||||
deserialize_enum! {
|
deserialize_enum! {
|
||||||
IpAddr IpAddrKind (V4; b"V4"; 0, V6; b"V6"; 1)
|
IpAddr IpAddrKind (V4; b"V4"; 0, V6; b"V6"; 1)
|
||||||
"`V4` or `V6`",
|
"`V4` or `V6`",
|
||||||
@@ -1604,7 +1598,7 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
|
|||||||
if deserializer.is_human_readable() {
|
if deserializer.is_human_readable() {
|
||||||
deserializer.deserialize_str(FromStrVisitor::new("socket address"))
|
deserializer.deserialize_str(FromStrVisitor::new("socket address"))
|
||||||
} else {
|
} else {
|
||||||
use lib::net::SocketAddr;
|
use crate::lib::net::SocketAddr;
|
||||||
deserialize_enum! {
|
deserialize_enum! {
|
||||||
SocketAddr SocketAddrKind (V4; b"V4"; 0, V6; b"V6"; 1)
|
SocketAddr SocketAddrKind (V4; b"V4"; 0, V6; b"V6"; 1)
|
||||||
"`V4` or `V6`",
|
"`V4` or `V6`",
|
||||||
@@ -1714,7 +1708,7 @@ impl<'de> Deserialize<'de> for PathBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(no_de_boxed_path)))]
|
#[cfg(feature = "std")]
|
||||||
forwarded_impl!((), Box<Path>, PathBuf::into_boxed_path);
|
forwarded_impl!((), Box<Path>, PathBuf::into_boxed_path);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -1748,7 +1742,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
|
|||||||
{
|
{
|
||||||
use std::os::unix::ffi::OsStringExt;
|
use std::os::unix::ffi::OsStringExt;
|
||||||
|
|
||||||
match try!(data.variant()) {
|
match tri!(data.variant()) {
|
||||||
(OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec),
|
(OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec),
|
||||||
(OsStringKind::Windows, _) => Err(Error::custom(
|
(OsStringKind::Windows, _) => Err(Error::custom(
|
||||||
"cannot deserialize Windows OS string on Unix",
|
"cannot deserialize Windows OS string on Unix",
|
||||||
@@ -1763,7 +1757,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
|
|||||||
{
|
{
|
||||||
use std::os::windows::ffi::OsStringExt;
|
use std::os::windows::ffi::OsStringExt;
|
||||||
|
|
||||||
match try!(data.variant()) {
|
match tri!(data.variant()) {
|
||||||
(OsStringKind::Windows, v) => v
|
(OsStringKind::Windows, v) => v
|
||||||
.newtype_variant::<Vec<u16>>()
|
.newtype_variant::<Vec<u16>>()
|
||||||
.map(|vec| OsString::from_wide(&vec)),
|
.map(|vec| OsString::from_wide(&vec)),
|
||||||
@@ -1795,30 +1789,6 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice);
|
|||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
||||||
|
|
||||||
#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))]
|
|
||||||
forwarded_impl! {
|
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
|
||||||
///
|
|
||||||
/// Deserializing a data structure containing `Arc` will not attempt to
|
|
||||||
/// deduplicate `Arc` references to the same data. Every deserialized `Arc`
|
|
||||||
/// will end up with a strong count of 1.
|
|
||||||
///
|
|
||||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
|
||||||
(T), Arc<T>, Arc::new
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(no_de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))]
|
|
||||||
forwarded_impl! {
|
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
|
||||||
///
|
|
||||||
/// Deserializing a data structure containing `Rc` will not attempt to
|
|
||||||
/// deduplicate `Rc` references to the same data. Every deserialized `Rc`
|
|
||||||
/// will end up with a strong count of 1.
|
|
||||||
///
|
|
||||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
|
||||||
(T), Rc<T>, Rc::new
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
||||||
where
|
where
|
||||||
@@ -1849,7 +1819,7 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
try!(Option::<T>::deserialize(deserializer));
|
tri!(Option::<T>::deserialize(deserializer));
|
||||||
Ok(RcWeak::new())
|
Ok(RcWeak::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1867,18 +1837,14 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
try!(Option::<T>::deserialize(deserializer));
|
tri!(Option::<T>::deserialize(deserializer));
|
||||||
Ok(ArcWeak::new())
|
Ok(ArcWeak::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
not(no_de_rc_dst),
|
|
||||||
feature = "rc",
|
|
||||||
any(feature = "std", feature = "alloc")
|
|
||||||
))]
|
|
||||||
macro_rules! box_forwarded_impl {
|
macro_rules! box_forwarded_impl {
|
||||||
(
|
(
|
||||||
$(#[doc = $doc:tt])*
|
$(#[doc = $doc:tt])*
|
||||||
@@ -1899,11 +1865,7 @@ macro_rules! box_forwarded_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
not(no_de_rc_dst),
|
|
||||||
feature = "rc",
|
|
||||||
any(feature = "std", feature = "alloc")
|
|
||||||
))]
|
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1915,11 +1877,7 @@ box_forwarded_impl! {
|
|||||||
Rc
|
Rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
not(no_de_rc_dst),
|
|
||||||
feature = "rc",
|
|
||||||
any(feature = "std", feature = "alloc")
|
|
||||||
))]
|
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1963,7 +1921,6 @@ forwarded_impl!((T), RwLock<T>, RwLock::new);
|
|||||||
// secs: u64,
|
// secs: u64,
|
||||||
// nanos: u32,
|
// nanos: u32,
|
||||||
// }
|
// }
|
||||||
#[cfg(any(feature = "std", not(no_core_duration)))]
|
|
||||||
impl<'de> Deserialize<'de> for Duration {
|
impl<'de> Deserialize<'de> for Duration {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -2011,7 +1968,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
b"secs" => Ok(Field::Secs),
|
b"secs" => Ok(Field::Secs),
|
||||||
b"nanos" => Ok(Field::Nanos),
|
b"nanos" => Ok(Field::Nanos),
|
||||||
_ => {
|
_ => {
|
||||||
let value = ::__private::from_utf8_lossy(value);
|
let value = crate::__private::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2046,19 +2003,19 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let secs: u64 = match try!(seq.next_element()) {
|
let secs: u64 = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(0, &self));
|
return Err(Error::invalid_length(0, &self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let nanos: u32 = match try!(seq.next_element()) {
|
let nanos: u32 = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(1, &self));
|
return Err(Error::invalid_length(1, &self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try!(check_overflow(secs, nanos));
|
tri!(check_overflow(secs, nanos));
|
||||||
Ok(Duration::new(secs, nanos))
|
Ok(Duration::new(secs, nanos))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2068,19 +2025,19 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
{
|
{
|
||||||
let mut secs: Option<u64> = None;
|
let mut secs: Option<u64> = None;
|
||||||
let mut nanos: Option<u32> = None;
|
let mut nanos: Option<u32> = None;
|
||||||
while let Some(key) = try!(map.next_key()) {
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
match key {
|
match key {
|
||||||
Field::Secs => {
|
Field::Secs => {
|
||||||
if secs.is_some() {
|
if secs.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("secs"));
|
return Err(<A::Error as Error>::duplicate_field("secs"));
|
||||||
}
|
}
|
||||||
secs = Some(try!(map.next_value()));
|
secs = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
Field::Nanos => {
|
Field::Nanos => {
|
||||||
if nanos.is_some() {
|
if nanos.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("nanos"));
|
return Err(<A::Error as Error>::duplicate_field("nanos"));
|
||||||
}
|
}
|
||||||
nanos = Some(try!(map.next_value()));
|
nanos = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2092,7 +2049,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
Some(nanos) => nanos,
|
Some(nanos) => nanos,
|
||||||
None => return Err(<A::Error as Error>::missing_field("nanos")),
|
None => return Err(<A::Error as Error>::missing_field("nanos")),
|
||||||
};
|
};
|
||||||
try!(check_overflow(secs, nanos));
|
tri!(check_overflow(secs, nanos));
|
||||||
Ok(Duration::new(secs, nanos))
|
Ok(Duration::new(secs, nanos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2184,19 +2141,19 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let secs: u64 = match try!(seq.next_element()) {
|
let secs: u64 = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(0, &self));
|
return Err(Error::invalid_length(0, &self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let nanos: u32 = match try!(seq.next_element()) {
|
let nanos: u32 = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(1, &self));
|
return Err(Error::invalid_length(1, &self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try!(check_overflow(secs, nanos));
|
tri!(check_overflow(secs, nanos));
|
||||||
Ok(Duration::new(secs, nanos))
|
Ok(Duration::new(secs, nanos))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2206,7 +2163,7 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
{
|
{
|
||||||
let mut secs: Option<u64> = None;
|
let mut secs: Option<u64> = None;
|
||||||
let mut nanos: Option<u32> = None;
|
let mut nanos: Option<u32> = None;
|
||||||
while let Some(key) = try!(map.next_key()) {
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
match key {
|
match key {
|
||||||
Field::Secs => {
|
Field::Secs => {
|
||||||
if secs.is_some() {
|
if secs.is_some() {
|
||||||
@@ -2214,7 +2171,7 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
"secs_since_epoch",
|
"secs_since_epoch",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
secs = Some(try!(map.next_value()));
|
secs = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
Field::Nanos => {
|
Field::Nanos => {
|
||||||
if nanos.is_some() {
|
if nanos.is_some() {
|
||||||
@@ -2222,7 +2179,7 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
"nanos_since_epoch",
|
"nanos_since_epoch",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
nanos = Some(try!(map.next_value()));
|
nanos = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2234,13 +2191,13 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
Some(nanos) => nanos,
|
Some(nanos) => nanos,
|
||||||
None => return Err(<A::Error as Error>::missing_field("nanos_since_epoch")),
|
None => return Err(<A::Error as Error>::missing_field("nanos_since_epoch")),
|
||||||
};
|
};
|
||||||
try!(check_overflow(secs, nanos));
|
tri!(check_overflow(secs, nanos));
|
||||||
Ok(Duration::new(secs, nanos))
|
Ok(Duration::new(secs, nanos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];
|
const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];
|
||||||
let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
|
let duration = tri!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
|
||||||
#[cfg(not(no_systemtime_checked_add))]
|
#[cfg(not(no_systemtime_checked_add))]
|
||||||
let ret = UNIX_EPOCH
|
let ret = UNIX_EPOCH
|
||||||
.checked_add(duration)
|
.checked_add(duration)
|
||||||
@@ -2269,7 +2226,7 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let (start, end) = try!(deserializer.deserialize_struct(
|
let (start, end) = tri!(deserializer.deserialize_struct(
|
||||||
"Range",
|
"Range",
|
||||||
range::FIELDS,
|
range::FIELDS,
|
||||||
range::RangeVisitor {
|
range::RangeVisitor {
|
||||||
@@ -2281,7 +2238,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(no_range_inclusive))]
|
|
||||||
impl<'de, Idx> Deserialize<'de> for RangeInclusive<Idx>
|
impl<'de, Idx> Deserialize<'de> for RangeInclusive<Idx>
|
||||||
where
|
where
|
||||||
Idx: Deserialize<'de>,
|
Idx: Deserialize<'de>,
|
||||||
@@ -2290,7 +2246,7 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let (start, end) = try!(deserializer.deserialize_struct(
|
let (start, end) = tri!(deserializer.deserialize_struct(
|
||||||
"RangeInclusive",
|
"RangeInclusive",
|
||||||
range::FIELDS,
|
range::FIELDS,
|
||||||
range::RangeVisitor {
|
range::RangeVisitor {
|
||||||
@@ -2303,9 +2259,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod range {
|
mod range {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["start", "end"];
|
pub const FIELDS: &[&str] = &["start", "end"];
|
||||||
|
|
||||||
@@ -2351,7 +2307,7 @@ mod range {
|
|||||||
b"start" => Ok(Field::Start),
|
b"start" => Ok(Field::Start),
|
||||||
b"end" => Ok(Field::End),
|
b"end" => Ok(Field::End),
|
||||||
_ => {
|
_ => {
|
||||||
let value = ::__private::from_utf8_lossy(value);
|
let value = crate::__private::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2381,13 +2337,13 @@ mod range {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let start: Idx = match try!(seq.next_element()) {
|
let start: Idx = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(0, &self));
|
return Err(Error::invalid_length(0, &self));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let end: Idx = match try!(seq.next_element()) {
|
let end: Idx = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(1, &self));
|
return Err(Error::invalid_length(1, &self));
|
||||||
@@ -2402,19 +2358,19 @@ mod range {
|
|||||||
{
|
{
|
||||||
let mut start: Option<Idx> = None;
|
let mut start: Option<Idx> = None;
|
||||||
let mut end: Option<Idx> = None;
|
let mut end: Option<Idx> = None;
|
||||||
while let Some(key) = try!(map.next_key()) {
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
match key {
|
match key {
|
||||||
Field::Start => {
|
Field::Start => {
|
||||||
if start.is_some() {
|
if start.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("start"));
|
return Err(<A::Error as Error>::duplicate_field("start"));
|
||||||
}
|
}
|
||||||
start = Some(try!(map.next_value()));
|
start = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
Field::End => {
|
Field::End => {
|
||||||
if end.is_some() {
|
if end.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("end"));
|
return Err(<A::Error as Error>::duplicate_field("end"));
|
||||||
}
|
}
|
||||||
end = Some(try!(map.next_value()));
|
end = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2448,7 +2404,7 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let start = try!(deserializer.deserialize_struct(
|
let start = tri!(deserializer.deserialize_struct(
|
||||||
"RangeFrom",
|
"RangeFrom",
|
||||||
range_from::FIELDS,
|
range_from::FIELDS,
|
||||||
range_from::RangeFromVisitor {
|
range_from::RangeFromVisitor {
|
||||||
@@ -2461,9 +2417,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod range_from {
|
mod range_from {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["end"];
|
pub const FIELDS: &[&str] = &["end"];
|
||||||
|
|
||||||
@@ -2506,7 +2462,7 @@ mod range_from {
|
|||||||
match value {
|
match value {
|
||||||
b"end" => Ok(Field::End),
|
b"end" => Ok(Field::End),
|
||||||
_ => {
|
_ => {
|
||||||
let value = ::__private::from_utf8_lossy(value);
|
let value = crate::__private::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2536,7 +2492,7 @@ mod range_from {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let end: Idx = match try!(seq.next_element()) {
|
let end: Idx = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(0, &self));
|
return Err(Error::invalid_length(0, &self));
|
||||||
@@ -2550,13 +2506,13 @@ mod range_from {
|
|||||||
A: MapAccess<'de>,
|
A: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut end: Option<Idx> = None;
|
let mut end: Option<Idx> = None;
|
||||||
while let Some(key) = try!(map.next_key()) {
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
match key {
|
match key {
|
||||||
Field::End => {
|
Field::End => {
|
||||||
if end.is_some() {
|
if end.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("end"));
|
return Err(<A::Error as Error>::duplicate_field("end"));
|
||||||
}
|
}
|
||||||
end = Some(try!(map.next_value()));
|
end = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2586,7 +2542,7 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let end = try!(deserializer.deserialize_struct(
|
let end = tri!(deserializer.deserialize_struct(
|
||||||
"RangeTo",
|
"RangeTo",
|
||||||
range_to::FIELDS,
|
range_to::FIELDS,
|
||||||
range_to::RangeToVisitor {
|
range_to::RangeToVisitor {
|
||||||
@@ -2599,9 +2555,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod range_to {
|
mod range_to {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["start"];
|
pub const FIELDS: &[&str] = &["start"];
|
||||||
|
|
||||||
@@ -2644,7 +2600,7 @@ mod range_to {
|
|||||||
match value {
|
match value {
|
||||||
b"start" => Ok(Field::Start),
|
b"start" => Ok(Field::Start),
|
||||||
_ => {
|
_ => {
|
||||||
let value = ::__private::from_utf8_lossy(value);
|
let value = crate::__private::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2674,7 +2630,7 @@ mod range_to {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let start: Idx = match try!(seq.next_element()) {
|
let start: Idx = match tri!(seq.next_element()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::invalid_length(0, &self));
|
return Err(Error::invalid_length(0, &self));
|
||||||
@@ -2688,13 +2644,13 @@ mod range_to {
|
|||||||
A: MapAccess<'de>,
|
A: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut start: Option<Idx> = None;
|
let mut start: Option<Idx> = None;
|
||||||
while let Some(key) = try!(map.next_key()) {
|
while let Some(key) = tri!(map.next_key()) {
|
||||||
match key {
|
match key {
|
||||||
Field::Start => {
|
Field::Start => {
|
||||||
if start.is_some() {
|
if start.is_some() {
|
||||||
return Err(<A::Error as Error>::duplicate_field("start"));
|
return Err(<A::Error as Error>::duplicate_field("start"));
|
||||||
}
|
}
|
||||||
start = Some(try!(map.next_value()));
|
start = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2709,7 +2665,6 @@ mod range_to {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
|
||||||
impl<'de, T> Deserialize<'de> for Bound<T>
|
impl<'de, T> Deserialize<'de> for Bound<T>
|
||||||
where
|
where
|
||||||
T: Deserialize<'de>,
|
T: Deserialize<'de>,
|
||||||
@@ -2801,7 +2756,7 @@ where
|
|||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: EnumAccess<'de>,
|
||||||
{
|
{
|
||||||
match try!(data.variant()) {
|
match tri!(data.variant()) {
|
||||||
(Field::Unbounded, v) => v.unit_variant().map(|()| Bound::Unbounded),
|
(Field::Unbounded, v) => v.unit_variant().map(|()| Bound::Unbounded),
|
||||||
(Field::Included, v) => v.newtype_variant().map(Bound::Included),
|
(Field::Included, v) => v.newtype_variant().map(Bound::Included),
|
||||||
(Field::Excluded, v) => v.newtype_variant().map(Bound::Excluded),
|
(Field::Excluded, v) => v.newtype_variant().map(Bound::Excluded),
|
||||||
@@ -2910,7 +2865,7 @@ where
|
|||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: EnumAccess<'de>,
|
||||||
{
|
{
|
||||||
match try!(data.variant()) {
|
match tri!(data.variant()) {
|
||||||
(Field::Ok, v) => v.newtype_variant().map(Ok),
|
(Field::Ok, v) => v.newtype_variant().map(Ok),
|
||||||
(Field::Err, v) => v.newtype_variant().map(Err),
|
(Field::Err, v) => v.newtype_variant().map(Err),
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -112,7 +112,7 @@
|
|||||||
//! [derive section of the manual]: https://serde.rs/derive.html
|
//! [derive section of the manual]: https://serde.rs/derive.html
|
||||||
//! [data formats]: https://serde.rs/#data-formats
|
//! [data formats]: https://serde.rs/#data-formats
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -126,15 +126,15 @@ mod utf8;
|
|||||||
|
|
||||||
pub use self::ignored_any::IgnoredAny;
|
pub use self::ignored_any::IgnoredAny;
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use crate::std_error::Error as StdError;
|
||||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use core::error::Error as StdError;
|
pub use core::error::Error as StdError;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use std::error::Error as StdError;
|
pub use std::error::Error as StdError;
|
||||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
|
||||||
#[doc(no_inline)]
|
|
||||||
pub use std_error::Error as StdError;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -569,7 +569,7 @@ pub trait Deserialize<'de>: Sized {
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
// Default implementation just delegates to `deserialize` impl.
|
// Default implementation just delegates to `deserialize` impl.
|
||||||
*place = try!(Deserialize::deserialize(deserializer));
|
*place = tri!(Deserialize::deserialize(deserializer));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1229,11 +1229,11 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn __deserialize_content<V>(
|
fn __deserialize_content<V>(
|
||||||
self,
|
self,
|
||||||
_: ::actually_private::T,
|
_: crate::actually_private::T,
|
||||||
visitor: V,
|
visitor: V,
|
||||||
) -> Result<::private::de::Content<'de>, Self::Error>
|
) -> Result<crate::__private::de::Content<'de>, Self::Error>
|
||||||
where
|
where
|
||||||
V: Visitor<'de, Value = ::private::de::Content<'de>>,
|
V: Visitor<'de, Value = crate::__private::de::Content<'de>>,
|
||||||
{
|
{
|
||||||
self.deserialize_any(visitor)
|
self.deserialize_any(visitor)
|
||||||
}
|
}
|
||||||
@@ -1834,9 +1834,9 @@ pub trait MapAccess<'de> {
|
|||||||
K: DeserializeSeed<'de>,
|
K: DeserializeSeed<'de>,
|
||||||
V: DeserializeSeed<'de>,
|
V: DeserializeSeed<'de>,
|
||||||
{
|
{
|
||||||
match try!(self.next_key_seed(kseed)) {
|
match tri!(self.next_key_seed(kseed)) {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
let value = try!(self.next_value_seed(vseed));
|
let value = tri!(self.next_value_seed(vseed));
|
||||||
Ok(Some((key, value)))
|
Ok(Some((key, value)))
|
||||||
}
|
}
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
@@ -2284,12 +2284,12 @@ impl Display for OneOf {
|
|||||||
1 => write!(formatter, "`{}`", self.names[0]),
|
1 => write!(formatter, "`{}`", self.names[0]),
|
||||||
2 => write!(formatter, "`{}` or `{}`", self.names[0], self.names[1]),
|
2 => write!(formatter, "`{}` or `{}`", self.names[0], self.names[1]),
|
||||||
_ => {
|
_ => {
|
||||||
try!(write!(formatter, "one of "));
|
tri!(write!(formatter, "one of "));
|
||||||
for (i, alt) in self.names.iter().enumerate() {
|
for (i, alt) in self.names.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
try!(write!(formatter, ", "));
|
tri!(write!(formatter, ", "));
|
||||||
}
|
}
|
||||||
try!(write!(formatter, "`{}`", alt));
|
tri!(write!(formatter, "`{}`", alt));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use de::{Deserialize, DeserializeSeed, Deserializer};
|
use crate::de::{Deserialize, DeserializeSeed, Deserializer};
|
||||||
|
|
||||||
/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.
|
/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
const TAG_CONT: u8 = 0b1000_0000;
|
const TAG_CONT: u8 = 0b1000_0000;
|
||||||
const TAG_TWO_B: u8 = 0b1100_0000;
|
const TAG_TWO_B: u8 = 0b1100_0000;
|
||||||
|
|||||||
+18
-16
@@ -21,12 +21,12 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use self::private::{First, Second};
|
use self::private::{First, Second};
|
||||||
use __private::size_hint;
|
use crate::__private::size_hint;
|
||||||
use de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
|
use crate::de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
|
||||||
use ser;
|
use crate::ser;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -937,8 +937,8 @@ where
|
|||||||
where
|
where
|
||||||
V: de::Visitor<'de>,
|
V: de::Visitor<'de>,
|
||||||
{
|
{
|
||||||
let v = try!(visitor.visit_seq(&mut self));
|
let v = tri!(visitor.visit_seq(&mut self));
|
||||||
try!(self.end());
|
tri!(self.end());
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1162,8 +1162,8 @@ where
|
|||||||
where
|
where
|
||||||
V: de::Visitor<'de>,
|
V: de::Visitor<'de>,
|
||||||
{
|
{
|
||||||
let value = try!(visitor.visit_map(&mut self));
|
let value = tri!(visitor.visit_map(&mut self));
|
||||||
try!(self.end());
|
tri!(self.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1171,8 +1171,8 @@ where
|
|||||||
where
|
where
|
||||||
V: de::Visitor<'de>,
|
V: de::Visitor<'de>,
|
||||||
{
|
{
|
||||||
let value = try!(visitor.visit_seq(&mut self));
|
let value = tri!(visitor.visit_seq(&mut self));
|
||||||
try!(self.end());
|
tri!(self.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1236,8 +1236,8 @@ where
|
|||||||
{
|
{
|
||||||
match self.next_pair() {
|
match self.next_pair() {
|
||||||
Some((key, value)) => {
|
Some((key, value)) => {
|
||||||
let key = try!(kseed.deserialize(key.into_deserializer()));
|
let key = tri!(kseed.deserialize(key.into_deserializer()));
|
||||||
let value = try!(vseed.deserialize(value.into_deserializer()));
|
let value = tri!(vseed.deserialize(value.into_deserializer()));
|
||||||
Ok(Some((key, value)))
|
Ok(Some((key, value)))
|
||||||
}
|
}
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
@@ -1341,7 +1341,7 @@ where
|
|||||||
V: de::Visitor<'de>,
|
V: de::Visitor<'de>,
|
||||||
{
|
{
|
||||||
let mut pair_visitor = PairVisitor(Some(self.0), Some(self.1), PhantomData);
|
let mut pair_visitor = PairVisitor(Some(self.0), Some(self.1), PhantomData);
|
||||||
let pair = try!(visitor.visit_seq(&mut pair_visitor));
|
let pair = tri!(visitor.visit_seq(&mut pair_visitor));
|
||||||
if pair_visitor.1.is_none() {
|
if pair_visitor.1.is_none() {
|
||||||
Ok(pair)
|
Ok(pair)
|
||||||
} else {
|
} else {
|
||||||
@@ -1501,7 +1501,7 @@ where
|
|||||||
where
|
where
|
||||||
T: de::DeserializeSeed<'de>,
|
T: de::DeserializeSeed<'de>,
|
||||||
{
|
{
|
||||||
match try!(self.map.next_key_seed(seed)) {
|
match tri!(self.map.next_key_seed(seed)) {
|
||||||
Some(key) => Ok((key, private::map_as_enum(self.map))),
|
Some(key) => Ok((key, private::map_as_enum(self.map))),
|
||||||
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
|
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
|
||||||
}
|
}
|
||||||
@@ -1546,9 +1546,11 @@ where
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mod private {
|
mod private {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::{self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor};
|
use crate::de::{
|
||||||
|
self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct UnitOnly<E> {
|
pub struct UnitOnly<E> {
|
||||||
marker: PhantomData<E>,
|
marker: PhantomData<E>,
|
||||||
|
|||||||
+8
-26
@@ -93,7 +93,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.178")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.180")]
|
||||||
// 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
|
||||||
@@ -177,14 +177,16 @@ mod lib {
|
|||||||
|
|
||||||
pub use self::core::cell::{Cell, RefCell};
|
pub use self::core::cell::{Cell, RefCell};
|
||||||
pub use self::core::clone::{self, Clone};
|
pub use self::core::clone::{self, Clone};
|
||||||
|
pub use self::core::cmp::Reverse;
|
||||||
pub use self::core::convert::{self, From, Into};
|
pub use self::core::convert::{self, From, Into};
|
||||||
pub use self::core::default::{self, Default};
|
pub use self::core::default::{self, Default};
|
||||||
pub use self::core::fmt::{self, Debug, Display};
|
pub use self::core::fmt::{self, Debug, Display};
|
||||||
pub use self::core::marker::{self, PhantomData};
|
pub use self::core::marker::{self, PhantomData};
|
||||||
pub use self::core::num::Wrapping;
|
pub use self::core::num::Wrapping;
|
||||||
pub use self::core::ops::{Range, RangeFrom, RangeTo};
|
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
|
||||||
pub use self::core::option::{self, Option};
|
pub use self::core::option::{self, Option};
|
||||||
pub use self::core::result::{self, Result};
|
pub use self::core::result::{self, Result};
|
||||||
|
pub use self::core::time::Duration;
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::borrow::{Cow, ToOwned};
|
pub use alloc::borrow::{Cow, ToOwned};
|
||||||
@@ -222,7 +224,7 @@ mod lib {
|
|||||||
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||||
|
|
||||||
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
|
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
|
||||||
pub use core::ffi::CStr;
|
pub use self::core::ffi::CStr;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::ffi::CStr;
|
pub use std::ffi::CStr;
|
||||||
|
|
||||||
@@ -249,18 +251,6 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{SystemTime, UNIX_EPOCH};
|
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(no_collections_bound), no_ops_bound))]
|
|
||||||
pub use std::collections::Bound;
|
|
||||||
|
|
||||||
#[cfg(not(no_core_reverse))]
|
|
||||||
pub use self::core::cmp::Reverse;
|
|
||||||
|
|
||||||
#[cfg(not(no_ops_bound))]
|
|
||||||
pub use self::core::ops::Bound;
|
|
||||||
|
|
||||||
#[cfg(not(no_range_inclusive))]
|
|
||||||
pub use self::core::ops::RangeInclusive;
|
|
||||||
|
|
||||||
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
|
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
|
||||||
pub use std::sync::atomic::{
|
pub use std::sync::atomic::{
|
||||||
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
||||||
@@ -281,16 +271,13 @@ mod lib {
|
|||||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
|
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
|
||||||
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
|
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", not(no_core_duration)))]
|
|
||||||
pub use self::core::time::Duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of this crate's error handling needs the `From::from` error conversion
|
// None of this crate's error handling needs the `From::from` error conversion
|
||||||
// performed implicitly by the `?` operator or the standard library's `try!`
|
// performed implicitly by the `?` operator or the standard library's `try!`
|
||||||
// macro. This simplified macro gives a 5.5% improvement in compile time
|
// macro. This simplified macro gives a 5.5% improvement in compile time
|
||||||
// compared to standard `try!`, and 9% improvement compared to `?`.
|
// compared to standard `try!`, and 9% improvement compared to `?`.
|
||||||
macro_rules! try {
|
macro_rules! tri {
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
match $expr {
|
match $expr {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
@@ -311,20 +298,15 @@ pub mod de;
|
|||||||
pub mod ser;
|
pub mod ser;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use de::{Deserialize, Deserializer};
|
pub use crate::de::{Deserialize, Deserializer};
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use ser::{Serialize, Serializer};
|
pub use crate::ser::{Serialize, Serializer};
|
||||||
|
|
||||||
// Used by generated code and doc tests. Not public API.
|
// Used by generated code and doc tests. Not public API.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[path = "private/mod.rs"]
|
#[path = "private/mod.rs"]
|
||||||
pub mod __private;
|
pub mod __private;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use self::__private as export;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use self::__private as private;
|
|
||||||
|
|
||||||
#[path = "de/seed.rs"]
|
#[path = "de/seed.rs"]
|
||||||
mod seed;
|
mod seed;
|
||||||
|
|
||||||
|
|||||||
+45
-183
@@ -1,10 +1,10 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use de::value::{BorrowedBytesDeserializer, BytesDeserializer};
|
use crate::de::value::{BorrowedBytesDeserializer, BytesDeserializer};
|
||||||
use de::{Deserialize, Deserializer, Error, IntoDeserializer, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, IntoDeserializer, Visitor};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
use de::{DeserializeSeed, MapAccess, Unexpected};
|
use crate::de::{DeserializeSeed, MapAccess, Unexpected};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub use self::content::{
|
pub use self::content::{
|
||||||
@@ -13,7 +13,7 @@ pub use self::content::{
|
|||||||
TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
|
TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use seed::InPlaceSeed;
|
pub use crate::seed::InPlaceSeed;
|
||||||
|
|
||||||
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
||||||
/// otherwise it is an error.
|
/// otherwise it is an error.
|
||||||
@@ -203,11 +203,12 @@ mod content {
|
|||||||
// This issue is tracking making some of this stuff public:
|
// This issue is tracking making some of this stuff public:
|
||||||
// https://github.com/serde-rs/serde/issues/741
|
// https://github.com/serde-rs/serde/issues/741
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use __private::size_hint;
|
use crate::__private::size_hint;
|
||||||
use actually_private;
|
use crate::actually_private;
|
||||||
use de::{
|
use crate::de::value::{MapDeserializer, SeqDeserializer};
|
||||||
|
use crate::de::{
|
||||||
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
|
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
|
||||||
MapAccess, SeqAccess, Unexpected, Visitor,
|
MapAccess, SeqAccess, Unexpected, Visitor,
|
||||||
};
|
};
|
||||||
@@ -299,6 +300,17 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de, E> de::IntoDeserializer<'de, E> for Content<'de>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
type Deserializer = ContentDeserializer<'de, E>;
|
||||||
|
|
||||||
|
fn into_deserializer(self) -> Self::Deserializer {
|
||||||
|
ContentDeserializer::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ContentVisitor<'de> {
|
struct ContentVisitor<'de> {
|
||||||
value: PhantomData<Content<'de>>,
|
value: PhantomData<Content<'de>>,
|
||||||
}
|
}
|
||||||
@@ -476,7 +488,7 @@ mod content {
|
|||||||
{
|
{
|
||||||
let mut vec =
|
let mut vec =
|
||||||
Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));
|
Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));
|
||||||
while let Some(e) = try!(visitor.next_element()) {
|
while let Some(e) = tri!(visitor.next_element()) {
|
||||||
vec.push(e);
|
vec.push(e);
|
||||||
}
|
}
|
||||||
Ok(Content::Seq(vec))
|
Ok(Content::Seq(vec))
|
||||||
@@ -490,7 +502,7 @@ mod content {
|
|||||||
Vec::<(Content, Content)>::with_capacity(
|
Vec::<(Content, Content)>::with_capacity(
|
||||||
size_hint::cautious::<(Content, Content)>(visitor.size_hint()),
|
size_hint::cautious::<(Content, Content)>(visitor.size_hint()),
|
||||||
);
|
);
|
||||||
while let Some(kv) = try!(visitor.next_entry()) {
|
while let Some(kv) = tri!(visitor.next_entry()) {
|
||||||
vec.push(kv);
|
vec.push(kv);
|
||||||
}
|
}
|
||||||
Ok(Content::Map(vec))
|
Ok(Content::Map(vec))
|
||||||
@@ -833,14 +845,14 @@ mod content {
|
|||||||
where
|
where
|
||||||
S: SeqAccess<'de>,
|
S: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let tag = match try!(seq.next_element()) {
|
let tag = match tri!(seq.next_element()) {
|
||||||
Some(tag) => tag,
|
Some(tag) => tag,
|
||||||
None => {
|
None => {
|
||||||
return Err(de::Error::missing_field(self.tag_name));
|
return Err(de::Error::missing_field(self.tag_name));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let rest = de::value::SeqAccessDeserializer::new(seq);
|
let rest = de::value::SeqAccessDeserializer::new(seq);
|
||||||
Ok((tag, try!(Content::deserialize(rest))))
|
Ok((tag, tri!(Content::deserialize(rest))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
||||||
@@ -852,16 +864,16 @@ mod content {
|
|||||||
Content,
|
Content,
|
||||||
Content,
|
Content,
|
||||||
)>(map.size_hint()));
|
)>(map.size_hint()));
|
||||||
while let Some(k) = try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
while let Some(k) = tri!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||||
match k {
|
match k {
|
||||||
TagOrContent::Tag => {
|
TagOrContent::Tag => {
|
||||||
if tag.is_some() {
|
if tag.is_some() {
|
||||||
return Err(de::Error::duplicate_field(self.tag_name));
|
return Err(de::Error::duplicate_field(self.tag_name));
|
||||||
}
|
}
|
||||||
tag = Some(try!(map.next_value()));
|
tag = Some(tri!(map.next_value()));
|
||||||
}
|
}
|
||||||
TagOrContent::Content(k) => {
|
TagOrContent::Content(k) => {
|
||||||
let v = try!(map.next_value());
|
let v = tri!(map.next_value());
|
||||||
vec.push((k, v));
|
vec.push((k, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1074,9 +1086,9 @@ mod content {
|
|||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let seq = content.into_iter().map(ContentDeserializer::new);
|
let seq = content.into_iter().map(ContentDeserializer::new);
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
let mut seq_visitor = SeqDeserializer::new(seq);
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
||||||
try!(seq_visitor.end());
|
tri!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,9 +1103,9 @@ mod content {
|
|||||||
let map = content
|
let map = content
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
||||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
let mut map_visitor = MapDeserializer::new(map);
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
let value = tri!(visitor.visit_map(&mut map_visitor));
|
||||||
try!(map_visitor.end());
|
tri!(map_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1569,7 +1581,7 @@ mod content {
|
|||||||
{
|
{
|
||||||
match self.value {
|
match self.value {
|
||||||
Some(Content::Seq(v)) => {
|
Some(Content::Seq(v)) => {
|
||||||
de::Deserializer::deserialize_any(SeqDeserializer::new(v), visitor)
|
de::Deserializer::deserialize_any(SeqDeserializer::new(v.into_iter()), visitor)
|
||||||
}
|
}
|
||||||
Some(other) => Err(de::Error::invalid_type(
|
Some(other) => Err(de::Error::invalid_type(
|
||||||
other.unexpected(),
|
other.unexpected(),
|
||||||
@@ -1592,10 +1604,10 @@ mod content {
|
|||||||
{
|
{
|
||||||
match self.value {
|
match self.value {
|
||||||
Some(Content::Map(v)) => {
|
Some(Content::Map(v)) => {
|
||||||
de::Deserializer::deserialize_any(MapDeserializer::new(v), visitor)
|
de::Deserializer::deserialize_any(MapDeserializer::new(v.into_iter()), visitor)
|
||||||
}
|
}
|
||||||
Some(Content::Seq(v)) => {
|
Some(Content::Seq(v)) => {
|
||||||
de::Deserializer::deserialize_any(SeqDeserializer::new(v), visitor)
|
de::Deserializer::deserialize_any(SeqDeserializer::new(v.into_iter()), visitor)
|
||||||
}
|
}
|
||||||
Some(other) => Err(de::Error::invalid_type(
|
Some(other) => Err(de::Error::invalid_type(
|
||||||
other.unexpected(),
|
other.unexpected(),
|
||||||
@@ -1609,156 +1621,6 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SeqDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
iter: <Vec<Content<'de>> as IntoIterator>::IntoIter,
|
|
||||||
err: PhantomData<E>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> SeqDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
fn new(vec: Vec<Content<'de>>) -> Self {
|
|
||||||
SeqDeserializer {
|
|
||||||
iter: vec.into_iter(),
|
|
||||||
err: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> de::Deserializer<'de> for SeqDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
|
||||||
where
|
|
||||||
V: de::Visitor<'de>,
|
|
||||||
{
|
|
||||||
let len = self.iter.len();
|
|
||||||
if len == 0 {
|
|
||||||
visitor.visit_unit()
|
|
||||||
} else {
|
|
||||||
let ret = try!(visitor.visit_seq(&mut self));
|
|
||||||
let remaining = self.iter.len();
|
|
||||||
if remaining == 0 {
|
|
||||||
Ok(ret)
|
|
||||||
} else {
|
|
||||||
Err(de::Error::invalid_length(len, &"fewer elements in array"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
|
||||||
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
|
|
||||||
bytes byte_buf option unit unit_struct newtype_struct seq tuple
|
|
||||||
tuple_struct map struct enum identifier ignored_any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> de::SeqAccess<'de> for SeqDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
|
||||||
where
|
|
||||||
T: de::DeserializeSeed<'de>,
|
|
||||||
{
|
|
||||||
match self.iter.next() {
|
|
||||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)).map(Some),
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> Option<usize> {
|
|
||||||
size_hint::from_bounds(&self.iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct MapDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
iter: <Vec<(Content<'de>, Content<'de>)> as IntoIterator>::IntoIter,
|
|
||||||
value: Option<Content<'de>>,
|
|
||||||
err: PhantomData<E>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> MapDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
fn new(map: Vec<(Content<'de>, Content<'de>)>) -> Self {
|
|
||||||
MapDeserializer {
|
|
||||||
iter: map.into_iter(),
|
|
||||||
value: None,
|
|
||||||
err: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> de::MapAccess<'de> for MapDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
|
||||||
where
|
|
||||||
T: de::DeserializeSeed<'de>,
|
|
||||||
{
|
|
||||||
match self.iter.next() {
|
|
||||||
Some((key, value)) => {
|
|
||||||
self.value = Some(value);
|
|
||||||
seed.deserialize(ContentDeserializer::new(key)).map(Some)
|
|
||||||
}
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
|
||||||
where
|
|
||||||
T: de::DeserializeSeed<'de>,
|
|
||||||
{
|
|
||||||
match self.value.take() {
|
|
||||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)),
|
|
||||||
None => Err(de::Error::custom("value is missing")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> Option<usize> {
|
|
||||||
size_hint::from_bounds(&self.iter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> de::Deserializer<'de> for MapDeserializer<'de, E>
|
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
||||||
where
|
|
||||||
V: de::Visitor<'de>,
|
|
||||||
{
|
|
||||||
visitor.visit_map(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
|
||||||
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
|
|
||||||
bytes byte_buf option unit unit_struct newtype_struct seq tuple
|
|
||||||
tuple_struct map struct enum identifier ignored_any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub struct ContentRefDeserializer<'a, 'de: 'a, E> {
|
pub struct ContentRefDeserializer<'a, 'de: 'a, E> {
|
||||||
content: &'a Content<'de>,
|
content: &'a Content<'de>,
|
||||||
@@ -1820,9 +1682,9 @@ mod content {
|
|||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let seq = content.iter().map(ContentRefDeserializer::new);
|
let seq = content.iter().map(ContentRefDeserializer::new);
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
let mut seq_visitor = SeqDeserializer::new(seq);
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
||||||
try!(seq_visitor.end());
|
tri!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1840,9 +1702,9 @@ mod content {
|
|||||||
ContentRefDeserializer::new(v),
|
ContentRefDeserializer::new(v),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
let mut map_visitor = MapDeserializer::new(map);
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
let value = tri!(visitor.visit_map(&mut map_visitor));
|
||||||
try!(map_visitor.end());
|
tri!(map_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2362,7 +2224,7 @@ mod content {
|
|||||||
if len == 0 {
|
if len == 0 {
|
||||||
visitor.visit_unit()
|
visitor.visit_unit()
|
||||||
} else {
|
} else {
|
||||||
let ret = try!(visitor.visit_seq(&mut self));
|
let ret = tri!(visitor.visit_seq(&mut self));
|
||||||
let remaining = self.iter.len();
|
let remaining = self.iter.len();
|
||||||
if remaining == 0 {
|
if remaining == 0 {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
@@ -2541,7 +2403,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
M: MapAccess<'de>,
|
M: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
while try!(access.next_entry::<IgnoredAny, IgnoredAny>()).is_some() {}
|
while tri!(access.next_entry::<IgnoredAny, IgnoredAny>()).is_some() {}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Used only by Serde doc tests. Not public API.
|
// Used only by Serde doc tests. Not public API.
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use ser;
|
use crate::ser;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
+11
-11
@@ -8,25 +8,25 @@ pub mod size_hint;
|
|||||||
// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
|
// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
|
||||||
pub mod doc;
|
pub mod doc;
|
||||||
|
|
||||||
pub use lib::clone::Clone;
|
pub use crate::lib::clone::Clone;
|
||||||
pub use lib::convert::{From, Into};
|
pub use crate::lib::convert::{From, Into};
|
||||||
pub use lib::default::Default;
|
pub use crate::lib::default::Default;
|
||||||
pub use lib::fmt::{self, Formatter};
|
pub use crate::lib::fmt::{self, Formatter};
|
||||||
pub use lib::marker::PhantomData;
|
pub use crate::lib::marker::PhantomData;
|
||||||
pub use lib::option::Option::{self, None, Some};
|
pub use crate::lib::option::Option::{self, None, Some};
|
||||||
pub use lib::ptr;
|
pub use crate::lib::ptr;
|
||||||
pub use lib::result::Result::{self, Err, Ok};
|
pub use crate::lib::result::Result::{self, Err, Ok};
|
||||||
|
|
||||||
pub use self::string::from_utf8_lossy;
|
pub use self::string::from_utf8_lossy;
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||||
pub use lib::{ToString, Vec};
|
pub use crate::lib::{ToString, Vec};
|
||||||
|
|
||||||
#[cfg(not(no_core_try_from))]
|
#[cfg(not(no_core_try_from))]
|
||||||
pub use lib::convert::TryFrom;
|
pub use crate::lib::convert::TryFrom;
|
||||||
|
|
||||||
mod string {
|
mod string {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
|
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
|
||||||
|
|||||||
+113
-66
@@ -1,6 +1,6 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
|
use crate::ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
use self::content::{
|
use self::content::{
|
||||||
@@ -182,14 +182,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(1)));
|
let mut map = tri!(self.delegate.serialize_map(Some(1)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(1)));
|
let mut map = tri!(self.delegate.serialize_map(Some(1)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,9 +199,9 @@ where
|
|||||||
_: u32,
|
_: u32,
|
||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
) -> Result<Self::Ok, Self::Error> {
|
) -> Result<Self::Ok, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
let mut map = tri!(self.delegate.serialize_map(Some(2)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
try!(map.serialize_entry(inner_variant, &()));
|
tri!(map.serialize_entry(inner_variant, &()));
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,9 +226,9 @@ where
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
let mut map = tri!(self.delegate.serialize_map(Some(2)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
try!(map.serialize_entry(inner_variant, inner_value));
|
tri!(map.serialize_entry(inner_variant, inner_value));
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,9 +269,9 @@ where
|
|||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
let mut map = tri!(self.delegate.serialize_map(Some(2)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
try!(map.serialize_key(inner_variant));
|
tri!(map.serialize_key(inner_variant));
|
||||||
Ok(SerializeTupleVariantAsMapValue::new(
|
Ok(SerializeTupleVariantAsMapValue::new(
|
||||||
map,
|
map,
|
||||||
inner_variant,
|
inner_variant,
|
||||||
@@ -280,8 +280,8 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(len.map(|len| len + 1)));
|
let mut map = tri!(self.delegate.serialize_map(len.map(|len| len + 1)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
Ok(map)
|
Ok(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,8 +290,8 @@ where
|
|||||||
name: &'static str,
|
name: &'static str,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeStruct, Self::Error> {
|
) -> Result<Self::SerializeStruct, Self::Error> {
|
||||||
let mut state = try!(self.delegate.serialize_struct(name, len + 1));
|
let mut state = tri!(self.delegate.serialize_struct(name, len + 1));
|
||||||
try!(state.serialize_field(self.tag, self.variant_name));
|
tri!(state.serialize_field(self.tag, self.variant_name));
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,9 +316,9 @@ where
|
|||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
let mut map = tri!(self.delegate.serialize_map(Some(2)));
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||||
try!(map.serialize_key(inner_variant));
|
tri!(map.serialize_key(inner_variant));
|
||||||
Ok(SerializeStructVariantAsMapValue::new(
|
Ok(SerializeStructVariantAsMapValue::new(
|
||||||
map,
|
map,
|
||||||
inner_variant,
|
inner_variant,
|
||||||
@@ -337,9 +337,9 @@ where
|
|||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
mod content {
|
mod content {
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use ser::{self, Serialize, Serializer};
|
use crate::ser::{self, Serialize, Serializer};
|
||||||
|
|
||||||
pub struct SerializeTupleVariantAsMapValue<M> {
|
pub struct SerializeTupleVariantAsMapValue<M> {
|
||||||
map: M,
|
map: M,
|
||||||
@@ -368,13 +368,13 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<M::Error>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||||
self.fields.push(value);
|
self.fields.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(mut self) -> Result<M::Ok, M::Error> {
|
fn end(mut self) -> Result<M::Ok, M::Error> {
|
||||||
try!(self
|
tri!(self
|
||||||
.map
|
.map
|
||||||
.serialize_value(&Content::TupleStruct(self.name, self.fields)));
|
.serialize_value(&Content::TupleStruct(self.name, self.fields)));
|
||||||
self.map.end()
|
self.map.end()
|
||||||
@@ -412,13 +412,13 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<M::Error>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||||
self.fields.push((key, value));
|
self.fields.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(mut self) -> Result<M::Ok, M::Error> {
|
fn end(mut self) -> Result<M::Ok, M::Error> {
|
||||||
try!(self
|
tri!(self
|
||||||
.map
|
.map
|
||||||
.serialize_value(&Content::Struct(self.name, self.fields)));
|
.serialize_value(&Content::Struct(self.name, self.fields)));
|
||||||
self.map.end()
|
self.map.end()
|
||||||
@@ -499,50 +499,50 @@ mod content {
|
|||||||
}
|
}
|
||||||
Content::Seq(ref elements) => elements.serialize(serializer),
|
Content::Seq(ref elements) => elements.serialize(serializer),
|
||||||
Content::Tuple(ref elements) => {
|
Content::Tuple(ref elements) => {
|
||||||
use ser::SerializeTuple;
|
use crate::ser::SerializeTuple;
|
||||||
let mut tuple = try!(serializer.serialize_tuple(elements.len()));
|
let mut tuple = tri!(serializer.serialize_tuple(elements.len()));
|
||||||
for e in elements {
|
for e in elements {
|
||||||
try!(tuple.serialize_element(e));
|
tri!(tuple.serialize_element(e));
|
||||||
}
|
}
|
||||||
tuple.end()
|
tuple.end()
|
||||||
}
|
}
|
||||||
Content::TupleStruct(n, ref fields) => {
|
Content::TupleStruct(n, ref fields) => {
|
||||||
use ser::SerializeTupleStruct;
|
use crate::ser::SerializeTupleStruct;
|
||||||
let mut ts = try!(serializer.serialize_tuple_struct(n, fields.len()));
|
let mut ts = tri!(serializer.serialize_tuple_struct(n, fields.len()));
|
||||||
for f in fields {
|
for f in fields {
|
||||||
try!(ts.serialize_field(f));
|
tri!(ts.serialize_field(f));
|
||||||
}
|
}
|
||||||
ts.end()
|
ts.end()
|
||||||
}
|
}
|
||||||
Content::TupleVariant(n, i, v, ref fields) => {
|
Content::TupleVariant(n, i, v, ref fields) => {
|
||||||
use ser::SerializeTupleVariant;
|
use crate::ser::SerializeTupleVariant;
|
||||||
let mut tv = try!(serializer.serialize_tuple_variant(n, i, v, fields.len()));
|
let mut tv = tri!(serializer.serialize_tuple_variant(n, i, v, fields.len()));
|
||||||
for f in fields {
|
for f in fields {
|
||||||
try!(tv.serialize_field(f));
|
tri!(tv.serialize_field(f));
|
||||||
}
|
}
|
||||||
tv.end()
|
tv.end()
|
||||||
}
|
}
|
||||||
Content::Map(ref entries) => {
|
Content::Map(ref entries) => {
|
||||||
use ser::SerializeMap;
|
use crate::ser::SerializeMap;
|
||||||
let mut map = try!(serializer.serialize_map(Some(entries.len())));
|
let mut map = tri!(serializer.serialize_map(Some(entries.len())));
|
||||||
for (k, v) in entries {
|
for (k, v) in entries {
|
||||||
try!(map.serialize_entry(k, v));
|
tri!(map.serialize_entry(k, v));
|
||||||
}
|
}
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
Content::Struct(n, ref fields) => {
|
Content::Struct(n, ref fields) => {
|
||||||
use ser::SerializeStruct;
|
use crate::ser::SerializeStruct;
|
||||||
let mut s = try!(serializer.serialize_struct(n, fields.len()));
|
let mut s = tri!(serializer.serialize_struct(n, fields.len()));
|
||||||
for &(k, ref v) in fields {
|
for &(k, ref v) in fields {
|
||||||
try!(s.serialize_field(k, v));
|
tri!(s.serialize_field(k, v));
|
||||||
}
|
}
|
||||||
s.end()
|
s.end()
|
||||||
}
|
}
|
||||||
Content::StructVariant(n, i, v, ref fields) => {
|
Content::StructVariant(n, i, v, ref fields) => {
|
||||||
use ser::SerializeStructVariant;
|
use crate::ser::SerializeStructVariant;
|
||||||
let mut sv = try!(serializer.serialize_struct_variant(n, i, v, fields.len()));
|
let mut sv = tri!(serializer.serialize_struct_variant(n, i, v, fields.len()));
|
||||||
for &(k, ref v) in fields {
|
for &(k, ref v) in fields {
|
||||||
try!(sv.serialize_field(k, v));
|
tri!(sv.serialize_field(k, v));
|
||||||
}
|
}
|
||||||
sv.end()
|
sv.end()
|
||||||
}
|
}
|
||||||
@@ -639,7 +639,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
Ok(Content::Some(Box::new(try!(value.serialize(self)))))
|
Ok(Content::Some(Box::new(tri!(value.serialize(self)))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit(self) -> Result<Content, E> {
|
fn serialize_unit(self) -> Result<Content, E> {
|
||||||
@@ -669,7 +669,7 @@ mod content {
|
|||||||
{
|
{
|
||||||
Ok(Content::NewtypeStruct(
|
Ok(Content::NewtypeStruct(
|
||||||
name,
|
name,
|
||||||
Box::new(try!(value.serialize(self))),
|
Box::new(tri!(value.serialize(self))),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +687,7 @@ mod content {
|
|||||||
name,
|
name,
|
||||||
variant_index,
|
variant_index,
|
||||||
variant,
|
variant,
|
||||||
Box::new(try!(value.serialize(self))),
|
Box::new(tri!(value.serialize(self))),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,7 +786,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.elements.push(value);
|
self.elements.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -812,7 +812,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.elements.push(value);
|
self.elements.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -839,7 +839,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.fields.push(value);
|
self.fields.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -868,7 +868,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.fields.push(value);
|
self.fields.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -900,7 +900,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let key = try!(key.serialize(ContentSerializer::<E>::new()));
|
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
|
||||||
self.key = Some(key);
|
self.key = Some(key);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -913,7 +913,7 @@ mod content {
|
|||||||
.key
|
.key
|
||||||
.take()
|
.take()
|
||||||
.expect("serialize_value called before serialize_key");
|
.expect("serialize_value called before serialize_key");
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.entries.push((key, value));
|
self.entries.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -927,8 +927,8 @@ mod content {
|
|||||||
K: Serialize,
|
K: Serialize,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
let key = try!(key.serialize(ContentSerializer::<E>::new()));
|
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.entries.push((key, value));
|
self.entries.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -951,7 +951,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.fields.push((key, value));
|
self.fields.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -980,7 +980,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||||
self.fields.push((key, value));
|
self.fields.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1025,7 +1025,7 @@ where
|
|||||||
type SerializeTupleStruct = Impossible<Self::Ok, M::Error>;
|
type SerializeTupleStruct = Impossible<Self::Ok, M::Error>;
|
||||||
type SerializeMap = FlatMapSerializeMap<'a, M>;
|
type SerializeMap = FlatMapSerializeMap<'a, M>;
|
||||||
type SerializeStruct = FlatMapSerializeStruct<'a, M>;
|
type SerializeStruct = FlatMapSerializeStruct<'a, M>;
|
||||||
type SerializeTupleVariant = Impossible<Self::Ok, M::Error>;
|
type SerializeTupleVariant = FlatMapSerializeTupleVariantAsMapValue<'a, M>;
|
||||||
type SerializeStructVariant = FlatMapSerializeStructVariantAsMapValue<'a, M>;
|
type SerializeStructVariant = FlatMapSerializeStructVariantAsMapValue<'a, M>;
|
||||||
|
|
||||||
fn serialize_bool(self, _: bool) -> Result<Self::Ok, Self::Error> {
|
fn serialize_bool(self, _: bool) -> Result<Self::Ok, Self::Error> {
|
||||||
@@ -1133,7 +1133,7 @@ where
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
try!(self.0.serialize_key(variant));
|
tri!(self.0.serialize_key(variant));
|
||||||
self.0.serialize_value(value)
|
self.0.serialize_value(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1157,10 +1157,11 @@ where
|
|||||||
self,
|
self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: u32,
|
_: u32,
|
||||||
_: &'static str,
|
variant: &'static str,
|
||||||
_: usize,
|
_: usize,
|
||||||
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||||
Err(Self::bad_type(Unsupported::Enum))
|
tri!(self.0.serialize_key(variant));
|
||||||
|
Ok(FlatMapSerializeTupleVariantAsMapValue::new(self.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_map(self, _: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
fn serialize_map(self, _: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||||
@@ -1182,7 +1183,7 @@ where
|
|||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
_: usize,
|
_: usize,
|
||||||
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
||||||
try!(self.0.serialize_key(inner_variant));
|
tri!(self.0.serialize_key(inner_variant));
|
||||||
Ok(FlatMapSerializeStructVariantAsMapValue::new(
|
Ok(FlatMapSerializeStructVariantAsMapValue::new(
|
||||||
self.0,
|
self.0,
|
||||||
inner_variant,
|
inner_variant,
|
||||||
@@ -1259,6 +1260,52 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
pub struct FlatMapSerializeTupleVariantAsMapValue<'a, M: 'a> {
|
||||||
|
map: &'a mut M,
|
||||||
|
fields: Vec<Content>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
impl<'a, M> FlatMapSerializeTupleVariantAsMapValue<'a, M>
|
||||||
|
where
|
||||||
|
M: SerializeMap + 'a,
|
||||||
|
{
|
||||||
|
fn new(map: &'a mut M) -> Self {
|
||||||
|
FlatMapSerializeTupleVariantAsMapValue {
|
||||||
|
map,
|
||||||
|
fields: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
impl<'a, M> ser::SerializeTupleVariant for FlatMapSerializeTupleVariantAsMapValue<'a, M>
|
||||||
|
where
|
||||||
|
M: SerializeMap + 'a,
|
||||||
|
{
|
||||||
|
type Ok = ();
|
||||||
|
type Error = M::Error;
|
||||||
|
|
||||||
|
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||||
|
self.fields.push(value);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<(), Self::Error> {
|
||||||
|
tri!(self.map.serialize_value(&Content::Seq(self.fields)));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub struct FlatMapSerializeStructVariantAsMapValue<'a, M: 'a> {
|
pub struct FlatMapSerializeStructVariantAsMapValue<'a, M: 'a> {
|
||||||
map: &'a mut M,
|
map: &'a mut M,
|
||||||
@@ -1296,13 +1343,13 @@ where
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let value = try!(value.serialize(ContentSerializer::<M::Error>::new()));
|
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||||
self.fields.push((key, value));
|
self.fields.push((key, value));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end(self) -> Result<(), Self::Error> {
|
fn end(self) -> Result<(), Self::Error> {
|
||||||
try!(self
|
tri!(self
|
||||||
.map
|
.map
|
||||||
.serialize_value(&Content::Struct(self.name, self.fields)));
|
.serialize_value(&Content::Struct(self.name, self.fields)));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
pub fn from_bounds<I>(iter: &I) -> Option<usize>
|
pub fn from_bounds<I>(iter: &I) -> Option<usize>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
use ser::{Error, Impossible, Serialize, Serializer};
|
use crate::ser::{Error, Impossible, Serialize, Serializer};
|
||||||
|
|
||||||
impl Error for fmt::Error {
|
impl Error for fmt::Error {
|
||||||
fn custom<T: Display>(_msg: T) -> Self {
|
fn custom<T: Display>(_msg: T) -> Self {
|
||||||
|
|||||||
+23
-28
@@ -1,6 +1,6 @@
|
|||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use ser::{Error, Serialize, SerializeTuple, Serializer};
|
use crate::ser::{Error, Serialize, SerializeTuple, Serializer};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ impl<T> Serialize for [T; 0] {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
try!(serializer.serialize_tuple(0)).end()
|
tri!(serializer.serialize_tuple(0)).end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +149,9 @@ macro_rules! array_impls {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
let mut seq = try!(serializer.serialize_tuple($len));
|
let mut seq = tri!(serializer.serialize_tuple($len));
|
||||||
for e in self {
|
for e in self {
|
||||||
try!(seq.serialize_element(e));
|
tri!(seq.serialize_element(e));
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
@@ -248,9 +248,9 @@ where
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("Range", 2));
|
let mut state = tri!(serializer.serialize_struct("Range", 2));
|
||||||
try!(state.serialize_field("start", &self.start));
|
tri!(state.serialize_field("start", &self.start));
|
||||||
try!(state.serialize_field("end", &self.end));
|
tri!(state.serialize_field("end", &self.end));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,15 +266,14 @@ where
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("RangeFrom", 1));
|
let mut state = tri!(serializer.serialize_struct("RangeFrom", 1));
|
||||||
try!(state.serialize_field("start", &self.start));
|
tri!(state.serialize_field("start", &self.start));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(not(no_range_inclusive))]
|
|
||||||
impl<Idx> Serialize for RangeInclusive<Idx>
|
impl<Idx> Serialize for RangeInclusive<Idx>
|
||||||
where
|
where
|
||||||
Idx: Serialize,
|
Idx: Serialize,
|
||||||
@@ -284,9 +283,9 @@ where
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("RangeInclusive", 2));
|
let mut state = tri!(serializer.serialize_struct("RangeInclusive", 2));
|
||||||
try!(state.serialize_field("start", &self.start()));
|
tri!(state.serialize_field("start", &self.start()));
|
||||||
try!(state.serialize_field("end", &self.end()));
|
tri!(state.serialize_field("end", &self.end()));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,15 +301,14 @@ where
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("RangeTo", 1));
|
let mut state = tri!(serializer.serialize_struct("RangeTo", 1));
|
||||||
try!(state.serialize_field("end", &self.end));
|
tri!(state.serialize_field("end", &self.end));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
|
||||||
impl<T> Serialize for Bound<T>
|
impl<T> Serialize for Bound<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
@@ -367,9 +365,9 @@ macro_rules! tuple_impls {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
let mut tuple = try!(serializer.serialize_tuple($len));
|
let mut tuple = tri!(serializer.serialize_tuple($len));
|
||||||
$(
|
$(
|
||||||
try!(tuple.serialize_element(&self.$n));
|
tri!(tuple.serialize_element(&self.$n));
|
||||||
)+
|
)+
|
||||||
tuple.end()
|
tuple.end()
|
||||||
}
|
}
|
||||||
@@ -538,7 +536,6 @@ where
|
|||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
($($T:ident,)+) => {
|
($($T:ident,)+) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(not(no_num_nonzero))]
|
|
||||||
impl Serialize for num::$T {
|
impl Serialize for num::$T {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -662,16 +659,15 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(feature = "std", not(no_core_duration)))]
|
|
||||||
impl Serialize for Duration {
|
impl Serialize for Duration {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("Duration", 2));
|
let mut state = tri!(serializer.serialize_struct("Duration", 2));
|
||||||
try!(state.serialize_field("secs", &self.as_secs()));
|
tri!(state.serialize_field("secs", &self.as_secs()));
|
||||||
try!(state.serialize_field("nanos", &self.subsec_nanos()));
|
tri!(state.serialize_field("nanos", &self.subsec_nanos()));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -689,9 +685,9 @@ impl Serialize for SystemTime {
|
|||||||
Ok(duration_since_epoch) => duration_since_epoch,
|
Ok(duration_since_epoch) => duration_since_epoch,
|
||||||
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
|
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
|
||||||
};
|
};
|
||||||
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
let mut state = tri!(serializer.serialize_struct("SystemTime", 2));
|
||||||
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
tri!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
||||||
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
tri!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -963,7 +959,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(no_core_reverse))]
|
|
||||||
impl<T> Serialize for Reverse<T>
|
impl<T> Serialize for Reverse<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
//! This module contains `Impossible` serializer and its implementations.
|
//! This module contains `Impossible` serializer and its implementations.
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use ser::{
|
use crate::ser::{
|
||||||
self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
|
self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
|
||||||
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant,
|
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant,
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-37
@@ -107,7 +107,7 @@
|
|||||||
//! [derive section of the manual]: https://serde.rs/derive.html
|
//! [derive section of the manual]: https://serde.rs/derive.html
|
||||||
//! [data formats]: https://serde.rs/#data-formats
|
//! [data formats]: https://serde.rs/#data-formats
|
||||||
|
|
||||||
use lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
mod fmt;
|
mod fmt;
|
||||||
mod impls;
|
mod impls;
|
||||||
@@ -115,15 +115,15 @@ mod impossible;
|
|||||||
|
|
||||||
pub use self::impossible::Impossible;
|
pub use self::impossible::Impossible;
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use crate::std_error::Error as StdError;
|
||||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use core::error::Error as StdError;
|
pub use core::error::Error as StdError;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use std::error::Error as StdError;
|
pub use std::error::Error as StdError;
|
||||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
|
||||||
#[doc(no_inline)]
|
|
||||||
pub use std_error::Error as StdError;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -1279,22 +1279,9 @@ pub trait Serializer: Sized {
|
|||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
<I as IntoIterator>::Item: Serialize,
|
<I as IntoIterator>::Item: Serialize,
|
||||||
{
|
{
|
||||||
let iter = iter.into_iter();
|
let mut iter = iter.into_iter();
|
||||||
let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter)));
|
let mut serializer = tri!(self.serialize_seq(iterator_len_hint(&iter)));
|
||||||
|
tri!(iter.try_for_each(|item| serializer.serialize_element(&item)));
|
||||||
#[cfg(not(no_iterator_try_fold))]
|
|
||||||
{
|
|
||||||
let mut iter = iter;
|
|
||||||
try!(iter.try_for_each(|item| serializer.serialize_element(&item)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(no_iterator_try_fold)]
|
|
||||||
{
|
|
||||||
for item in iter {
|
|
||||||
try!(serializer.serialize_element(&item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
serializer.end()
|
serializer.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1330,22 +1317,9 @@ pub trait Serializer: Sized {
|
|||||||
V: Serialize,
|
V: Serialize,
|
||||||
I: IntoIterator<Item = (K, V)>,
|
I: IntoIterator<Item = (K, V)>,
|
||||||
{
|
{
|
||||||
let iter = iter.into_iter();
|
let mut iter = iter.into_iter();
|
||||||
let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter)));
|
let mut serializer = tri!(self.serialize_map(iterator_len_hint(&iter)));
|
||||||
|
tri!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value)));
|
||||||
#[cfg(not(no_iterator_try_fold))]
|
|
||||||
{
|
|
||||||
let mut iter = iter;
|
|
||||||
try!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(no_iterator_try_fold)]
|
|
||||||
{
|
|
||||||
for (key, value) in iter {
|
|
||||||
try!(serializer.serialize_entry(&key, &value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
serializer.end()
|
serializer.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1839,7 +1813,7 @@ pub trait SerializeMap {
|
|||||||
K: Serialize,
|
K: Serialize,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
{
|
{
|
||||||
try!(self.serialize_key(key));
|
tri!(self.serialize_key(key));
|
||||||
self.serialize_value(value)
|
self.serialize_value(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use lib::{Debug, Display};
|
use crate::lib::{Debug, Display};
|
||||||
|
|
||||||
/// Either a re-export of std::error::Error or a new identical trait, depending
|
/// Either a re-export of std::error::Error or a new identical trait, depending
|
||||||
/// on whether Serde's "std" feature is enabled.
|
/// on whether Serde's "std" feature is enabled.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.178" # remember to update html_root_url
|
version = "1.0.180" # 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>"]
|
||||||
categories = ["no-std", "no-std::no-alloc"]
|
categories = ["no-std", "no-std::no-alloc"]
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -23,7 +23,7 @@ proc-macro = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = "2.0.25"
|
syn = "2.0.28"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1", path = "../serde" }
|
serde = { version = "1", path = "../serde" }
|
||||||
|
|||||||
@@ -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.178")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.180")]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
|
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ path = "lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
syn = { version = "2.0.28", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|||||||
@@ -114,42 +114,6 @@ struct CollectOther {
|
|||||||
extra: HashMap<String, u32>,
|
extra: HashMap<String, u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
struct FlattenStructEnumWrapper {
|
|
||||||
#[serde(flatten)]
|
|
||||||
data: FlattenStructEnum,
|
|
||||||
#[serde(flatten)]
|
|
||||||
extra: HashMap<String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "snake_case")]
|
|
||||||
enum FlattenStructEnum {
|
|
||||||
InsertInteger { index: u32, value: u32 },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
struct FlattenStructTagContentEnumWrapper {
|
|
||||||
outer: u32,
|
|
||||||
#[serde(flatten)]
|
|
||||||
data: FlattenStructTagContentEnumNewtype,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
struct FlattenStructTagContentEnumNewtype(pub FlattenStructTagContentEnum);
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "snake_case", tag = "type", content = "value")]
|
|
||||||
enum FlattenStructTagContentEnum {
|
|
||||||
InsertInteger { index: u32, value: u32 },
|
|
||||||
NewtypeVariant(FlattenStructTagContentEnumNewtypeVariant),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
||||||
struct FlattenStructTagContentEnumNewtypeVariant {
|
|
||||||
value: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default_struct() {
|
fn test_default_struct() {
|
||||||
assert_de_tokens(
|
assert_de_tokens(
|
||||||
@@ -1643,149 +1607,6 @@ fn test_collect_other() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flatten_struct_enum() {
|
|
||||||
let mut extra = HashMap::new();
|
|
||||||
extra.insert("extra_key".into(), "extra value".into());
|
|
||||||
let change_request = FlattenStructEnumWrapper {
|
|
||||||
data: FlattenStructEnum::InsertInteger {
|
|
||||||
index: 0,
|
|
||||||
value: 42,
|
|
||||||
},
|
|
||||||
extra,
|
|
||||||
};
|
|
||||||
assert_de_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("insert_integer"),
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("index"),
|
|
||||||
Token::U32(0),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::MapEnd,
|
|
||||||
Token::Str("extra_key"),
|
|
||||||
Token::Str("extra value"),
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert_ser_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("insert_integer"),
|
|
||||||
Token::Struct {
|
|
||||||
len: 2,
|
|
||||||
name: "insert_integer",
|
|
||||||
},
|
|
||||||
Token::Str("index"),
|
|
||||||
Token::U32(0),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::StructEnd,
|
|
||||||
Token::Str("extra_key"),
|
|
||||||
Token::Str("extra value"),
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flatten_struct_tag_content_enum() {
|
|
||||||
let change_request = FlattenStructTagContentEnumWrapper {
|
|
||||||
outer: 42,
|
|
||||||
data: FlattenStructTagContentEnumNewtype(FlattenStructTagContentEnum::InsertInteger {
|
|
||||||
index: 0,
|
|
||||||
value: 42,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
assert_de_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("outer"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::Str("type"),
|
|
||||||
Token::Str("insert_integer"),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("index"),
|
|
||||||
Token::U32(0),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::MapEnd,
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert_ser_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("outer"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::Str("type"),
|
|
||||||
Token::Str("insert_integer"),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::Struct {
|
|
||||||
len: 2,
|
|
||||||
name: "insert_integer",
|
|
||||||
},
|
|
||||||
Token::Str("index"),
|
|
||||||
Token::U32(0),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::StructEnd,
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flatten_struct_tag_content_enum_newtype() {
|
|
||||||
let change_request = FlattenStructTagContentEnumWrapper {
|
|
||||||
outer: 42,
|
|
||||||
data: FlattenStructTagContentEnumNewtype(FlattenStructTagContentEnum::NewtypeVariant(
|
|
||||||
FlattenStructTagContentEnumNewtypeVariant { value: 23 },
|
|
||||||
)),
|
|
||||||
};
|
|
||||||
assert_de_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("outer"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::Str("type"),
|
|
||||||
Token::Str("newtype_variant"),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(23),
|
|
||||||
Token::MapEnd,
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
assert_ser_tokens(
|
|
||||||
&change_request,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("outer"),
|
|
||||||
Token::U32(42),
|
|
||||||
Token::Str("type"),
|
|
||||||
Token::Str("newtype_variant"),
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::Struct {
|
|
||||||
len: 1,
|
|
||||||
name: "FlattenStructTagContentEnumNewtypeVariant",
|
|
||||||
},
|
|
||||||
Token::Str("value"),
|
|
||||||
Token::U32(23),
|
|
||||||
Token::StructEnd,
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unknown_field_in_flatten() {
|
fn test_unknown_field_in_flatten() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@@ -2142,86 +1963,6 @@ fn test_lifetime_propagation_for_flatten() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flatten_enum_newtype() {
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
struct S {
|
|
||||||
#[serde(flatten)]
|
|
||||||
flat: E,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
enum E {
|
|
||||||
Q(HashMap<String, String>),
|
|
||||||
}
|
|
||||||
|
|
||||||
let e = E::Q({
|
|
||||||
let mut map = HashMap::new();
|
|
||||||
map.insert("k".to_owned(), "v".to_owned());
|
|
||||||
map
|
|
||||||
});
|
|
||||||
let s = S { flat: e };
|
|
||||||
|
|
||||||
assert_tokens(
|
|
||||||
&s,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("Q"),
|
|
||||||
Token::Map { len: Some(1) },
|
|
||||||
Token::Str("k"),
|
|
||||||
Token::Str("v"),
|
|
||||||
Token::MapEnd,
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flatten_internally_tagged() {
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
struct S {
|
|
||||||
#[serde(flatten)]
|
|
||||||
x: X,
|
|
||||||
#[serde(flatten)]
|
|
||||||
y: Y,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
#[serde(tag = "typeX")]
|
|
||||||
enum X {
|
|
||||||
A { a: i32 },
|
|
||||||
B { b: i32 },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
#[serde(tag = "typeY")]
|
|
||||||
enum Y {
|
|
||||||
C { c: i32 },
|
|
||||||
D { d: i32 },
|
|
||||||
}
|
|
||||||
|
|
||||||
let s = S {
|
|
||||||
x: X::B { b: 1 },
|
|
||||||
y: Y::D { d: 2 },
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_tokens(
|
|
||||||
&s,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("typeX"),
|
|
||||||
Token::Str("B"),
|
|
||||||
Token::Str("b"),
|
|
||||||
Token::I32(1),
|
|
||||||
Token::Str("typeY"),
|
|
||||||
Token::Str("D"),
|
|
||||||
Token::Str("d"),
|
|
||||||
Token::I32(2),
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_externally_tagged_enum_containing_flatten() {
|
fn test_externally_tagged_enum_containing_flatten() {
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@@ -2630,35 +2371,6 @@ fn test_partially_untagged_enum_desugared() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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]
|
#[test]
|
||||||
fn test_flatten_option() {
|
fn test_flatten_option() {
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@@ -2815,48 +2527,6 @@ fn test_internally_tagged_unit_enum_with_unknown_fields() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_flattened_internally_tagged_unit_enum_with_unknown_fields() {
|
|
||||||
#[derive(Deserialize, PartialEq, Debug)]
|
|
||||||
struct S {
|
|
||||||
#[serde(flatten)]
|
|
||||||
x: X,
|
|
||||||
#[serde(flatten)]
|
|
||||||
y: Y,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, PartialEq, Debug)]
|
|
||||||
#[serde(tag = "typeX")]
|
|
||||||
enum X {
|
|
||||||
A,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, PartialEq, Debug)]
|
|
||||||
#[serde(tag = "typeY")]
|
|
||||||
enum Y {
|
|
||||||
B { c: u32 },
|
|
||||||
}
|
|
||||||
|
|
||||||
let s = S {
|
|
||||||
x: X::A,
|
|
||||||
y: Y::B { c: 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_de_tokens(
|
|
||||||
&s,
|
|
||||||
&[
|
|
||||||
Token::Map { len: None },
|
|
||||||
Token::Str("typeX"),
|
|
||||||
Token::Str("A"),
|
|
||||||
Token::Str("typeY"),
|
|
||||||
Token::Str("B"),
|
|
||||||
Token::Str("c"),
|
|
||||||
Token::I32(0),
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flatten_any_after_flatten_struct() {
|
fn test_flatten_any_after_flatten_struct() {
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
@@ -3149,3 +2819,339 @@ fn test_expecting_message_identifier_enum() {
|
|||||||
r#"invalid type: map, expected something strange..."#,
|
r#"invalid type: map, expected something strange..."#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod flatten {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
mod enum_ {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
mod externally_tagged {
|
||||||
|
use super::*;
|
||||||
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct Flatten {
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: Enum,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
extra: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
enum Enum {
|
||||||
|
Newtype(HashMap<String, String>),
|
||||||
|
Tuple(u32, u32),
|
||||||
|
Struct { index: u32, value: u32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn newtype() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
data: Enum::Newtype(HashMap::from_iter([("key".into(), "value".into())])),
|
||||||
|
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("Newtype"), // variant
|
||||||
|
Token::Map { len: Some(1) },
|
||||||
|
Token::Str("key"),
|
||||||
|
Token::Str("value"),
|
||||||
|
Token::MapEnd,
|
||||||
|
Token::Str("extra_key"),
|
||||||
|
Token::Str("extra value"),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::tuple_variant
|
||||||
|
// Content::Seq case
|
||||||
|
// via FlatMapDeserializer::deserialize_enum
|
||||||
|
#[test]
|
||||||
|
fn tuple() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
data: Enum::Tuple(0, 42),
|
||||||
|
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("Tuple"), // variant
|
||||||
|
Token::Seq { len: Some(2) },
|
||||||
|
Token::U32(0),
|
||||||
|
Token::U32(42),
|
||||||
|
Token::SeqEnd,
|
||||||
|
Token::Str("extra_key"),
|
||||||
|
Token::Str("extra value"),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
|
||||||
|
// Content::Seq case
|
||||||
|
// via FlatMapDeserializer::deserialize_enum
|
||||||
|
#[test]
|
||||||
|
fn struct_from_seq() {
|
||||||
|
assert_de_tokens(
|
||||||
|
&Flatten {
|
||||||
|
data: Enum::Struct {
|
||||||
|
index: 0,
|
||||||
|
value: 42,
|
||||||
|
},
|
||||||
|
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("Struct"), // variant
|
||||||
|
Token::Seq { len: Some(2) },
|
||||||
|
Token::U32(0), // index
|
||||||
|
Token::U32(42), // value
|
||||||
|
Token::SeqEnd,
|
||||||
|
Token::Str("extra_key"),
|
||||||
|
Token::Str("extra value"),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
|
||||||
|
// Content::Map case
|
||||||
|
// via FlatMapDeserializer::deserialize_enum
|
||||||
|
#[test]
|
||||||
|
fn struct_from_map() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
data: Enum::Struct {
|
||||||
|
index: 0,
|
||||||
|
value: 42,
|
||||||
|
},
|
||||||
|
extra: HashMap::from_iter([("extra_key".into(), "extra value".into())]),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("Struct"), // variant
|
||||||
|
Token::Struct {
|
||||||
|
len: 2,
|
||||||
|
name: "Struct",
|
||||||
|
},
|
||||||
|
Token::Str("index"),
|
||||||
|
Token::U32(0),
|
||||||
|
Token::Str("value"),
|
||||||
|
Token::U32(42),
|
||||||
|
Token::StructEnd,
|
||||||
|
Token::Str("extra_key"),
|
||||||
|
Token::Str("extra value"),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod adjacently_tagged {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct Flatten {
|
||||||
|
outer: u32,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: NewtypeWrapper,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct NewtypeWrapper(pub Enum);
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "tag", content = "content")]
|
||||||
|
enum Enum {
|
||||||
|
Newtype(NewtypeVariant),
|
||||||
|
Struct { index: u32, value: u32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct NewtypeVariant {
|
||||||
|
value: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn struct_() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
outer: 42,
|
||||||
|
data: NewtypeWrapper(Enum::Struct {
|
||||||
|
index: 0,
|
||||||
|
value: 42,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("outer"),
|
||||||
|
Token::U32(42),
|
||||||
|
Token::Str("tag"),
|
||||||
|
Token::Str("Struct"),
|
||||||
|
Token::Str("content"),
|
||||||
|
Token::Struct {
|
||||||
|
len: 2,
|
||||||
|
name: "Struct",
|
||||||
|
},
|
||||||
|
Token::Str("index"),
|
||||||
|
Token::U32(0),
|
||||||
|
Token::Str("value"),
|
||||||
|
Token::U32(42),
|
||||||
|
Token::StructEnd,
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn newtype() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
outer: 42,
|
||||||
|
data: NewtypeWrapper(Enum::Newtype(NewtypeVariant { value: 23 })),
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("outer"),
|
||||||
|
Token::U32(42),
|
||||||
|
Token::Str("tag"),
|
||||||
|
Token::Str("Newtype"),
|
||||||
|
Token::Str("content"),
|
||||||
|
Token::Struct {
|
||||||
|
len: 1,
|
||||||
|
name: "NewtypeVariant",
|
||||||
|
},
|
||||||
|
Token::Str("value"),
|
||||||
|
Token::U32(23),
|
||||||
|
Token::StructEnd,
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod internally_tagged {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn structs() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct Flatten {
|
||||||
|
#[serde(flatten)]
|
||||||
|
x: X,
|
||||||
|
#[serde(flatten)]
|
||||||
|
y: Y,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "typeX")]
|
||||||
|
enum X {
|
||||||
|
A { a: i32 },
|
||||||
|
B { b: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "typeY")]
|
||||||
|
enum Y {
|
||||||
|
C { c: i32 },
|
||||||
|
D { d: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
x: X::B { b: 1 },
|
||||||
|
y: Y::D { d: 2 },
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("typeX"),
|
||||||
|
Token::Str("B"),
|
||||||
|
Token::Str("b"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::Str("typeY"),
|
||||||
|
Token::Str("D"),
|
||||||
|
Token::Str("d"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unit_enum_with_unknown_fields() {
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
struct Flatten {
|
||||||
|
#[serde(flatten)]
|
||||||
|
x: X,
|
||||||
|
#[serde(flatten)]
|
||||||
|
y: Y,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
#[serde(tag = "typeX")]
|
||||||
|
enum X {
|
||||||
|
A,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
#[serde(tag = "typeY")]
|
||||||
|
enum Y {
|
||||||
|
B { c: u32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Flatten {
|
||||||
|
x: X::A,
|
||||||
|
y: Y::B { c: 0 },
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("typeX"),
|
||||||
|
Token::Str("A"),
|
||||||
|
Token::Str("typeY"),
|
||||||
|
Token::Str("B"),
|
||||||
|
Token::Str("c"),
|
||||||
|
Token::I32(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod untagged {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct Flatten {
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: Enum,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum Enum {
|
||||||
|
Struct { a: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn struct_() {
|
||||||
|
assert_tokens(
|
||||||
|
&Flatten {
|
||||||
|
data: Enum::Struct { a: 0 },
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::I32(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1429,6 +1429,9 @@ fn test_enum_in_internally_tagged_enum() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::tuple_variant
|
||||||
|
// Content::Seq case
|
||||||
|
// via ContentDeserializer::deserialize_enum
|
||||||
assert_tokens(
|
assert_tokens(
|
||||||
&Outer::Inner(Inner::Tuple(1, 1)),
|
&Outer::Inner(Inner::Tuple(1, 1)),
|
||||||
&[
|
&[
|
||||||
@@ -1447,6 +1450,9 @@ fn test_enum_in_internally_tagged_enum() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
|
||||||
|
// Content::Map case
|
||||||
|
// via ContentDeserializer::deserialize_enum
|
||||||
assert_tokens(
|
assert_tokens(
|
||||||
&Outer::Inner(Inner::Struct { f: 1 }),
|
&Outer::Inner(Inner::Struct { f: 1 }),
|
||||||
&[
|
&[
|
||||||
@@ -1464,6 +1470,23 @@ fn test_enum_in_internally_tagged_enum() {
|
|||||||
Token::MapEnd,
|
Token::MapEnd,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Reaches crate::private::de::content::VariantDeserializer::struct_variant
|
||||||
|
// Content::Seq case
|
||||||
|
// via ContentDeserializer::deserialize_enum
|
||||||
|
assert_de_tokens(
|
||||||
|
&Outer::Inner(Inner::Struct { f: 1 }),
|
||||||
|
&[
|
||||||
|
Token::Map { len: Some(2) },
|
||||||
|
Token::Str("type"),
|
||||||
|
Token::Str("Inner"),
|
||||||
|
Token::Str("Struct"),
|
||||||
|
Token::Seq { len: Some(1) },
|
||||||
|
Token::U8(1), // f
|
||||||
|
Token::SeqEnd,
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user