mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 21:48:02 +00:00
Compare commits
157 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 89c4b02bf3 | |||
| eeb8e44cda | |||
| 785c2d9605 | |||
| d549f048e1 | |||
| 4c0dd63011 | |||
| 26fb134165 | |||
| 07e614b52b | |||
| b1f899fbe8 | |||
| b4f860e627 | |||
| d940fe1b49 | |||
| f2899a9e06 | |||
| 3aca38d2d3 | |||
| 30752ac4ff | |||
| b84e6ca4f5 | |||
| 87a2fb0f1a | |||
| 9eaf7b9824 | |||
| 7bde100237 | |||
| da7fc795ee | |||
| 4c5fec1363 | |||
| 6588b0ad37 | |||
| 0093f74cfe | |||
| 171c6da57a | |||
| 2dddc7796d | |||
| 8514f4119a | |||
| 98fb7d94aa | |||
| 31ca16d9bc | |||
| 9f72ce695e | |||
| c383e4f953 | |||
| a94d8750fb | |||
| b0d651be40 | |||
| d5a9c11b5c | |||
| 6bfe1c435a | |||
| a02da49b87 | |||
| 29dc6c3367 | |||
| a7f0bab078 | |||
| 3dc6829303 | |||
| 42e63ff942 | |||
| df07751e6f | |||
| 5445f1741b | |||
| 9d0f811221 | |||
| 36b9a859c4 | |||
| 59628d1712 | |||
| bee7470715 | |||
| 5a359e10f4 | |||
| 5e37ade519 | |||
| 1a9ffdbd0c | |||
| 2adb0e99b0 | |||
| 71ed1f2f12 | |||
| 47954502af | |||
| 4987fd15f7 | |||
| 8bfe0d0ac0 | |||
| 7c0e6bd18f | |||
| 41b9c33c2b | |||
| 28a775db22 | |||
| e999600f8f | |||
| d3492d8d36 | |||
| 48de0c51b0 | |||
| 93bda5f1dc | |||
| 2d75ef6b30 | |||
| f97160f715 | |||
| eb59c776ca | |||
| 9128201c78 | |||
| 2cbfd37072 | |||
| 0939214c51 | |||
| 8c60f5aea7 | |||
| da0ed4021d | |||
| 99f905403b | |||
| aa0654332d | |||
| af376c22c3 | |||
| 477eb7b70e | |||
| 026e91a68c | |||
| bfbedac919 | |||
| 4036ff88ed | |||
| 1b4da41f97 | |||
| f61d452814 | |||
| f9866097a0 | |||
| 77a6a9d4e1 | |||
| 547d843cca | |||
| 005cb84593 | |||
| fd5b5e9aa5 | |||
| 0647a7c1fe | |||
| 85c73ef8de | |||
| 5ba1796a7e | |||
| e52b7b380f | |||
| 84c7419652 | |||
| 536221b1f9 | |||
| fc55ac70d3 | |||
| 2afe5b4ef9 | |||
| b4ec2595c9 | |||
| c3ac7b675a | |||
| 24614e44bf | |||
| 9b868ef831 | |||
| c3eaf76430 | |||
| 32958dec3b | |||
| d64a97ba1e | |||
| c3df3372a1 | |||
| 8764353fe2 | |||
| e08c5de5dd | |||
| bc5af506bd | |||
| 28a092261b | |||
| 18dcae0a77 | |||
| 58c307f9cc | |||
| 8cc4809414 | |||
| 1179158def | |||
| 91aa40e749 | |||
| 595019e979 | |||
| b0d7917f88 | |||
| 8e6637a1e4 | |||
| 694fe05953 | |||
| f3dfd2a237 | |||
| 9e6158e9e6 | |||
| d577c4a2ce | |||
| fee0b82a40 | |||
| 7aafa26314 | |||
| d5bc546ca5 | |||
| 45ae217728 | |||
| b7b97dda73 | |||
| 5d3c563d46 | |||
| 376185458b | |||
| a8f14840ab | |||
| 9e32a40b1c | |||
| 87f635e54d | |||
| d4b2dfbde2 | |||
| f6ab0bc56f | |||
| 48cc2a6327 | |||
| 3202a6858a | |||
| b4f1bc16ff | |||
| 029ab46f71 | |||
| 220ca0ca9d | |||
| 20306f493a | |||
| cc865ac523 | |||
| 2d973c1805 | |||
| 6ca499b2dd | |||
| 1477028717 | |||
| 789740be0d | |||
| 8fe7539bb2 | |||
| f6623a3654 | |||
| c4fb923335 | |||
| 65b7eea775 | |||
| 01cd696fd1 | |||
| c13b3f7e68 | |||
| a6571ee0da | |||
| 6e38afff49 | |||
| 3d1b19ed90 | |||
| 5b24f88e73 | |||
| 74d06708dd | |||
| 3bfab6ef7f | |||
| 364cd8d8f7 | |||
| 9f8c579bf5 | |||
| eae7c2d684 | |||
| 3f43fca90d | |||
| 76449488ca | |||
| 00c4b0cef8 | |||
| 89139e2c11 | |||
| c9cab490f7 | |||
| 6a097eca93 | |||
| 84d1c5385d |
@@ -21,6 +21,11 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cd test_suite && cargo test --features unstable
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: Cargo.lock
|
||||
path: Cargo.lock
|
||||
|
||||
windows:
|
||||
name: Test suite (windows)
|
||||
@@ -84,6 +89,7 @@ jobs:
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{matrix.rust}}
|
||||
- run: sed -i '/"test_suite"/d' Cargo.toml
|
||||
- run: cd serde && cargo build --features rc
|
||||
- run: cd serde && cargo build --no-default-features
|
||||
- run: cd serde && cargo build
|
||||
@@ -95,6 +101,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.56.0
|
||||
- run: sed -i '/"test_suite"/d' Cargo.toml
|
||||
- run: cd serde && cargo check --no-default-features
|
||||
- run: cd serde && cargo check
|
||||
- run: cd serde_derive && cargo check
|
||||
@@ -106,6 +113,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.36.0
|
||||
- run: sed -i '/"test_suite"/d' Cargo.toml
|
||||
- run: cd serde && cargo build --no-default-features --features alloc
|
||||
|
||||
minimal:
|
||||
@@ -168,5 +176,6 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: dtolnay/install@cargo-outdated
|
||||
- run: cargo outdated --workspace --exit-code 1
|
||||
|
||||
+2
-2
@@ -46,8 +46,8 @@ fn main() {
|
||||
Serde is one of the most widely used Rust libraries so any place that Rustaceans
|
||||
congregate will be able to help you out. For chat, consider trying the
|
||||
[#rust-questions] or [#rust-beginners] channels of the unofficial community
|
||||
Discord (invite: <https://discord.gg/rust-lang-community>, the [#rust-usage] or
|
||||
[#beginners] channels of the official Rust Project Discord (invite:
|
||||
Discord (invite: <https://discord.gg/rust-lang-community>), the [#rust-usage]
|
||||
or [#beginners] channels of the official Rust Project Discord (invite:
|
||||
<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
|
||||
asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
|
||||
[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde"
|
||||
version = "1.0.197"
|
||||
version = "1.0.210"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
build = "build.rs"
|
||||
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||
@@ -29,7 +29,7 @@ features = ["derive", "rc"]
|
||||
[package.metadata.docs.rs]
|
||||
features = ["derive", "rc", "unstable"]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
# This cfg cannot be enabled, but it still forces Cargo to keep serde_derive's
|
||||
# version in lockstep with serde's, even if someone depends on the two crates
|
||||
@@ -37,7 +37,7 @@ rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
|
||||
# is compatible with exactly one serde release because the generated code
|
||||
# involves nonpublic APIs which are not bound by semver.
|
||||
[target.'cfg(any())'.dependencies]
|
||||
serde_derive = { version = "=1.0.197", path = "../serde_derive" }
|
||||
serde_derive = { version = "=1.0.210", path = "../serde_derive" }
|
||||
|
||||
|
||||
### FEATURES #################################################################
|
||||
|
||||
@@ -13,6 +13,23 @@ fn main() {
|
||||
None => return,
|
||||
};
|
||||
|
||||
if minor >= 77 {
|
||||
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_float_copysign)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_num_nonzero_signed)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_relaxed_trait_bounds)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)");
|
||||
}
|
||||
|
||||
let target = env::var("TARGET").unwrap();
|
||||
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
||||
|
||||
@@ -64,6 +81,30 @@ fn main() {
|
||||
if minor < 64 {
|
||||
println!("cargo:rustc-cfg=no_core_cstr");
|
||||
}
|
||||
|
||||
// Support for core::num::Saturating and std::num::Saturating stabilized in Rust 1.74
|
||||
// https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#stabilized-apis
|
||||
if minor < 74 {
|
||||
println!("cargo:rustc-cfg=no_core_num_saturating");
|
||||
}
|
||||
|
||||
// Support for core::net stabilized in Rust 1.77.
|
||||
// https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html
|
||||
if minor < 77 {
|
||||
println!("cargo:rustc-cfg=no_core_net");
|
||||
}
|
||||
|
||||
// Support for the `#[diagnostic]` tool attribute namespace
|
||||
// https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes
|
||||
if minor < 78 {
|
||||
println!("cargo:rustc-cfg=no_diagnostic_namespace");
|
||||
}
|
||||
|
||||
// The Error trait became available in core in 1.81.
|
||||
// https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror
|
||||
if minor < 81 {
|
||||
println!("cargo:rustc-cfg=no_core_error");
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_minor_version() -> Option<u32> {
|
||||
|
||||
+249
-137
@@ -39,7 +39,7 @@ impl<'de> Deserialize<'de> for () {
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||
impl<'de> Deserialize<'de> for ! {
|
||||
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -104,6 +104,28 @@ macro_rules! impl_deserialize_num {
|
||||
deserializer.$deserialize(NonZeroVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(no_core_num_saturating))]
|
||||
impl<'de> Deserialize<'de> for Saturating<$primitive> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct SaturatingVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for SaturatingVisitor {
|
||||
type Value = Saturating<$primitive>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("integer with support for saturating semantics")
|
||||
}
|
||||
|
||||
$($($method!(saturating $primitive $val : $visit);)*)*
|
||||
}
|
||||
|
||||
deserializer.$deserialize(SaturatingVisitor)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($primitive:ident, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {
|
||||
@@ -154,6 +176,15 @@ macro_rules! num_self {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
Ok(Saturating(v))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! num_as_self {
|
||||
@@ -179,6 +210,15 @@ macro_rules! num_as_self {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
Ok(Saturating(v as $primitive))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! num_as_copysign_self {
|
||||
@@ -235,6 +275,21 @@ macro_rules! int_to_int {
|
||||
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
if (v as i64) < $primitive::MIN as i64 {
|
||||
Ok(Saturating($primitive::MIN))
|
||||
} else if ($primitive::MAX as i64) < v as i64 {
|
||||
Ok(Saturating($primitive::MAX))
|
||||
} else {
|
||||
Ok(Saturating(v as $primitive))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! int_to_uint {
|
||||
@@ -265,6 +320,21 @@ macro_rules! int_to_uint {
|
||||
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
if v < 0 {
|
||||
Ok(Saturating(0))
|
||||
} else if ($primitive::MAX as u64) < v as u64 {
|
||||
Ok(Saturating($primitive::MAX))
|
||||
} else {
|
||||
Ok(Saturating(v as $primitive))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! uint_to_self {
|
||||
@@ -295,6 +365,19 @@ macro_rules! uint_to_self {
|
||||
Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
if v as u64 <= $primitive::MAX as u64 {
|
||||
Ok(Saturating(v as $primitive))
|
||||
} else {
|
||||
Ok(Saturating($primitive::MAX))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_deserialize_num! {
|
||||
@@ -427,6 +510,21 @@ macro_rules! num_128 {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(saturating $primitive:ident $ty:ident : $visit:ident) => {
|
||||
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
if (v as i128) < $primitive::MIN as i128 {
|
||||
Ok(Saturating($primitive::MIN))
|
||||
} else if ($primitive::MAX as u128) < v as u128 {
|
||||
Ok(Saturating($primitive::MAX))
|
||||
} else {
|
||||
Ok(Saturating(v as $primitive))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_deserialize_num! {
|
||||
@@ -597,7 +695,7 @@ impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de> Deserialize<'de> for String {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -741,7 +839,7 @@ impl<'de> Visitor<'de> for CStringVisitor {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de> Deserialize<'de> for CString {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -770,7 +868,7 @@ macro_rules! forwarded_impl {
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
(), Box<CStr>, CString::into_boxed_c_str
|
||||
}
|
||||
|
||||
@@ -852,7 +950,10 @@ struct PhantomDataVisitor<T: ?Sized> {
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'de, T: ?Sized> Visitor<'de> for PhantomDataVisitor<T> {
|
||||
impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
{
|
||||
type Value = PhantomData<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@@ -868,7 +969,10 @@ impl<'de, T: ?Sized> Visitor<'de> for PhantomDataVisitor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T: ?Sized> Deserialize<'de> for PhantomData<T> {
|
||||
impl<'de, T> Deserialize<'de> for PhantomData<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
@@ -982,7 +1086,7 @@ fn nop_reserve<T>(_seq: T, _n: usize) {}
|
||||
|
||||
seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BinaryHeap<T: Ord>,
|
||||
seq,
|
||||
BinaryHeap::clear,
|
||||
@@ -993,7 +1097,7 @@ seq_impl!(
|
||||
|
||||
seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BTreeSet<T: Eq + Ord>,
|
||||
seq,
|
||||
BTreeSet::clear,
|
||||
@@ -1004,7 +1108,7 @@ seq_impl!(
|
||||
|
||||
seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
LinkedList<T>,
|
||||
seq,
|
||||
LinkedList::clear,
|
||||
@@ -1015,7 +1119,7 @@ seq_impl!(
|
||||
|
||||
seq_impl!(
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
|
||||
seq,
|
||||
HashSet::clear,
|
||||
@@ -1026,7 +1130,7 @@ seq_impl!(
|
||||
|
||||
seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
VecDeque<T>,
|
||||
seq,
|
||||
VecDeque::clear,
|
||||
@@ -1038,7 +1142,7 @@ seq_impl!(
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, T> Deserialize<'de> for Vec<T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
@@ -1289,82 +1393,103 @@ array_impls! {
|
||||
macro_rules! tuple_impls {
|
||||
($($len:tt => ($($n:tt $name:ident)+))+) => {
|
||||
$(
|
||||
impl<'de, $($name: Deserialize<'de>),+> Deserialize<'de> for ($($name,)+) {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct TupleVisitor<$($name,)+> {
|
||||
marker: PhantomData<($($name,)+)>,
|
||||
}
|
||||
|
||||
impl<'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleVisitor<$($name,)+> {
|
||||
type Value = ($($name,)+);
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str(concat!("a tuple of size ", $len))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
$(
|
||||
let $name = match tri!(seq.next_element()) {
|
||||
Some(value) => value,
|
||||
None => return Err(Error::invalid_length($n, &self)),
|
||||
};
|
||||
)+
|
||||
|
||||
Ok(($($name,)+))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_tuple($len, TupleVisitor { marker: PhantomData })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct TupleInPlaceVisitor<'a, $($name: 'a,)+>(&'a mut ($($name,)+));
|
||||
|
||||
impl<'a, 'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleInPlaceVisitor<'a, $($name,)+> {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str(concat!("a tuple of size ", $len))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
$(
|
||||
if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
|
||||
return Err(Error::invalid_length($n, &self));
|
||||
}
|
||||
)+
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_tuple($len, TupleInPlaceVisitor(place))
|
||||
}
|
||||
#[cfg_attr(docsrs, doc(hidden))]
|
||||
impl<'de, $($name),+> Deserialize<'de> for ($($name,)+)
|
||||
where
|
||||
$($name: Deserialize<'de>,)+
|
||||
{
|
||||
tuple_impl_body!($len => ($($n $name)+));
|
||||
}
|
||||
)+
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! tuple_impl_body {
|
||||
($len:tt => ($($n:tt $name:ident)+)) => {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct TupleVisitor<$($name,)+> {
|
||||
marker: PhantomData<($($name,)+)>,
|
||||
}
|
||||
|
||||
impl<'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleVisitor<$($name,)+> {
|
||||
type Value = ($($name,)+);
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str(concat!("a tuple of size ", $len))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
$(
|
||||
let $name = match tri!(seq.next_element()) {
|
||||
Some(value) => value,
|
||||
None => return Err(Error::invalid_length($n, &self)),
|
||||
};
|
||||
)+
|
||||
|
||||
Ok(($($name,)+))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_tuple($len, TupleVisitor { marker: PhantomData })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct TupleInPlaceVisitor<'a, $($name: 'a,)+>(&'a mut ($($name,)+));
|
||||
|
||||
impl<'a, 'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleInPlaceVisitor<'a, $($name,)+> {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str(concat!("a tuple of size ", $len))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
{
|
||||
$(
|
||||
if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
|
||||
return Err(Error::invalid_length($n, &self));
|
||||
}
|
||||
)+
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_tuple($len, TupleInPlaceVisitor(place))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(fake_variadic))]
|
||||
#[cfg_attr(
|
||||
docsrs,
|
||||
doc = "This trait is implemented for tuples up to 16 items long."
|
||||
)]
|
||||
impl<'de, T> Deserialize<'de> for (T,)
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
tuple_impl_body!(1 => (0 T));
|
||||
}
|
||||
|
||||
tuple_impls! {
|
||||
1 => (0 T0)
|
||||
2 => (0 T0 1 T1)
|
||||
3 => (0 T0 1 T1 2 T2)
|
||||
4 => (0 T0 1 T1 2 T2 3 T3)
|
||||
@@ -1442,7 +1567,7 @@ macro_rules! map_impl {
|
||||
|
||||
map_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BTreeMap<K: Ord, V>,
|
||||
map,
|
||||
BTreeMap::new(),
|
||||
@@ -1450,7 +1575,7 @@ map_impl! {
|
||||
|
||||
map_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
|
||||
map,
|
||||
HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default()),
|
||||
@@ -1458,12 +1583,9 @@ map_impl! {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
macro_rules! parse_ip_impl {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
$ty:ty, $expecting:expr, $size:tt
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
($ty:ty, $expecting:expr, $size:tt) => {
|
||||
impl<'de> Deserialize<'de> for $ty {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1479,7 +1601,7 @@ macro_rules! parse_ip_impl {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
macro_rules! variant_identifier {
|
||||
(
|
||||
$name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
||||
@@ -1554,7 +1676,7 @@ macro_rules! variant_identifier {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
macro_rules! deserialize_enum {
|
||||
(
|
||||
$name:ident $name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
||||
@@ -1591,8 +1713,7 @@ macro_rules! deserialize_enum {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl<'de> Deserialize<'de> for net::IpAddr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1611,25 +1732,18 @@ impl<'de> Deserialize<'de> for net::IpAddr {
|
||||
}
|
||||
}
|
||||
|
||||
parse_ip_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
net::Ipv4Addr, "IPv4 address", 4
|
||||
}
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
parse_ip_impl!(net::Ipv4Addr, "IPv4 address", 4);
|
||||
|
||||
parse_ip_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
net::Ipv6Addr, "IPv6 address", 16
|
||||
}
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
parse_ip_impl!(net::Ipv6Addr, "IPv6 address", 16);
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
macro_rules! parse_socket_impl {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
$ty:ty, $expecting:tt,
|
||||
$new:expr,
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
impl<'de> Deserialize<'de> for $ty {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1645,8 +1759,7 @@ macro_rules! parse_socket_impl {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl<'de> Deserialize<'de> for net::SocketAddr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1665,16 +1778,14 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
parse_socket_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
net::SocketAddrV4, "IPv4 socket address",
|
||||
|(ip, port)| net::SocketAddrV4::new(ip, port),
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
parse_socket_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
net::SocketAddrV6, "IPv6 socket address",
|
||||
|(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0),
|
||||
}
|
||||
@@ -1710,7 +1821,7 @@ impl<'a> Visitor<'a> for PathVisitor {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<'de: 'a, 'a> Deserialize<'de> for &'a Path {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1765,7 +1876,7 @@ impl<'de> Visitor<'de> for PathBufVisitor {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<'de> Deserialize<'de> for PathBuf {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1777,7 +1888,7 @@ impl<'de> Deserialize<'de> for PathBuf {
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
(), Box<Path>, PathBuf::into_boxed_path
|
||||
}
|
||||
|
||||
@@ -1839,7 +1950,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
impl<'de> Deserialize<'de> for OsString {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -1853,33 +1964,33 @@ impl<'de> Deserialize<'de> for OsString {
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
(T), Box<T>, Box::new
|
||||
}
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
(T), Box<[T]>, Vec::into_boxed_slice
|
||||
}
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
(), Box<str>, String::into_boxed_str
|
||||
}
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
(), Box<OsStr>, OsString::into_boxed_os_str
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
|
||||
where
|
||||
T: ToOwned,
|
||||
T: ?Sized + ToOwned,
|
||||
T::Owned: Deserialize<'de>,
|
||||
{
|
||||
#[inline]
|
||||
@@ -1899,10 +2010,10 @@ where
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(
|
||||
doc_cfg,
|
||||
docsrs,
|
||||
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
|
||||
)]
|
||||
impl<'de, T: ?Sized> Deserialize<'de> for RcWeak<T>
|
||||
impl<'de, T> Deserialize<'de> for RcWeak<T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
@@ -1921,10 +2032,10 @@ where
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(
|
||||
doc_cfg,
|
||||
docsrs,
|
||||
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
|
||||
)]
|
||||
impl<'de, T: ?Sized> Deserialize<'de> for ArcWeak<T>
|
||||
impl<'de, T> Deserialize<'de> for ArcWeak<T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
@@ -1945,8 +2056,9 @@ macro_rules! box_forwarded_impl {
|
||||
$t:ident
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
impl<'de, T: ?Sized> Deserialize<'de> for $t<T>
|
||||
impl<'de, T> Deserialize<'de> for $t<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
Box<T>: Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
@@ -1968,7 +2080,7 @@ box_forwarded_impl! {
|
||||
///
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
Rc
|
||||
}
|
||||
|
||||
@@ -1981,7 +2093,7 @@ box_forwarded_impl! {
|
||||
///
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
Arc
|
||||
}
|
||||
|
||||
@@ -2005,13 +2117,13 @@ forwarded_impl! {
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
(T), Mutex<T>, Mutex::new
|
||||
}
|
||||
|
||||
forwarded_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
(T), RwLock<T>, RwLock::new
|
||||
}
|
||||
|
||||
@@ -2166,7 +2278,7 @@ impl<'de> Deserialize<'de> for Duration {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<'de> Deserialize<'de> for SystemTime {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -3002,7 +3114,7 @@ macro_rules! atomic_impl {
|
||||
($($ty:ident $size:expr)*) => {
|
||||
$(
|
||||
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
|
||||
impl<'de> Deserialize<'de> for $ty {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
@@ -3034,13 +3146,13 @@ atomic_impl! {
|
||||
AtomicU64 "64"
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
struct FromStrVisitor<T> {
|
||||
expecting: &'static str,
|
||||
ty: PhantomData<T>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl<T> FromStrVisitor<T> {
|
||||
fn new(expecting: &'static str) -> Self {
|
||||
FromStrVisitor {
|
||||
@@ -3050,7 +3162,7 @@ impl<T> FromStrVisitor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl<'de, T> Visitor<'de> for FromStrVisitor<T>
|
||||
where
|
||||
T: str::FromStr,
|
||||
|
||||
+28
-18
@@ -118,17 +118,16 @@ use crate::lib::*;
|
||||
|
||||
pub mod value;
|
||||
|
||||
mod format;
|
||||
mod ignored_any;
|
||||
mod impls;
|
||||
pub(crate) mod size_hint;
|
||||
|
||||
pub use self::ignored_any::IgnoredAny;
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::std_error::Error as StdError;
|
||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
||||
#[cfg(not(any(feature = "std", no_core_error)))]
|
||||
#[doc(no_inline)]
|
||||
pub use core::error::Error as StdError;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -532,6 +531,13 @@ impl<'a> Display for Expected + 'a {
|
||||
/// deserializer lifetimes] for a more detailed explanation of these lifetimes.
|
||||
///
|
||||
/// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html
|
||||
#[cfg_attr(
|
||||
not(no_diagnostic_namespace),
|
||||
diagnostic::on_unimplemented(
|
||||
note = "for local types consider adding `#[derive(serde::Deserialize)]` to your `{Self}` type",
|
||||
note = "for types from other crates check whether the crate offers a `serde` feature flag",
|
||||
)
|
||||
)]
|
||||
pub trait Deserialize<'de>: Sized {
|
||||
/// Deserialize this value from the given Serde deserializer.
|
||||
///
|
||||
@@ -1367,7 +1373,7 @@ pub trait Visitor<'de>: Sized {
|
||||
E: Error,
|
||||
{
|
||||
let mut buf = [0u8; 58];
|
||||
let mut writer = format::Buf::new(&mut buf);
|
||||
let mut writer = crate::format::Buf::new(&mut buf);
|
||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
|
||||
Err(Error::invalid_type(
|
||||
Unexpected::Other(writer.as_str()),
|
||||
@@ -1429,7 +1435,7 @@ pub trait Visitor<'de>: Sized {
|
||||
E: Error,
|
||||
{
|
||||
let mut buf = [0u8; 57];
|
||||
let mut writer = format::Buf::new(&mut buf);
|
||||
let mut writer = crate::format::Buf::new(&mut buf);
|
||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
|
||||
Err(Error::invalid_type(
|
||||
Unexpected::Other(writer.as_str()),
|
||||
@@ -1525,7 +1531,7 @@ pub trait Visitor<'de>: Sized {
|
||||
/// `String`.
|
||||
#[inline]
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
@@ -1584,7 +1590,7 @@ pub trait Visitor<'de>: Sized {
|
||||
/// The default implementation forwards to `visit_bytes` and then drops the
|
||||
/// `Vec<u8>`.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
@@ -1735,9 +1741,9 @@ pub trait SeqAccess<'de> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, A: ?Sized> SeqAccess<'de> for &'a mut A
|
||||
impl<'de, 'a, A> SeqAccess<'de> for &'a mut A
|
||||
where
|
||||
A: SeqAccess<'de>,
|
||||
A: ?Sized + SeqAccess<'de>,
|
||||
{
|
||||
type Error = A::Error;
|
||||
|
||||
@@ -1888,9 +1894,9 @@ pub trait MapAccess<'de> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, A: ?Sized> MapAccess<'de> for &'a mut A
|
||||
impl<'de, 'a, A> MapAccess<'de> for &'a mut A
|
||||
where
|
||||
A: MapAccess<'de>,
|
||||
A: ?Sized + MapAccess<'de>,
|
||||
{
|
||||
type Error = A::Error;
|
||||
|
||||
@@ -2312,13 +2318,17 @@ impl Display for WithDecimalPoint {
|
||||
}
|
||||
}
|
||||
|
||||
let mut writer = LookForDecimalPoint {
|
||||
formatter,
|
||||
has_decimal_point: false,
|
||||
};
|
||||
tri!(write!(writer, "{}", self.0));
|
||||
if !writer.has_decimal_point {
|
||||
tri!(formatter.write_str(".0"));
|
||||
if self.0.is_finite() {
|
||||
let mut writer = LookForDecimalPoint {
|
||||
formatter,
|
||||
has_decimal_point: false,
|
||||
};
|
||||
tri!(write!(writer, "{}", self.0));
|
||||
if !writer.has_decimal_point {
|
||||
tri!(formatter.write_str(".0"));
|
||||
}
|
||||
} else {
|
||||
tri!(write!(formatter, "{}", self.0));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+12
-12
@@ -112,7 +112,7 @@ impl Debug for Error {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
&self.err
|
||||
@@ -185,14 +185,14 @@ impl<E> Debug for UnitDeserializer<E> {
|
||||
|
||||
/// A deserializer that cannot be instantiated.
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||
pub struct NeverDeserializer<E> {
|
||||
never: !,
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||
impl<'de, E> IntoDeserializer<'de, E> for !
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -565,7 +565,7 @@ impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
|
||||
|
||||
/// A deserializer holding a `String`.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
pub struct StringDeserializer<E> {
|
||||
value: String,
|
||||
marker: PhantomData<E>,
|
||||
@@ -582,7 +582,7 @@ impl<E> Clone for StringDeserializer<E> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, E> IntoDeserializer<'de, E> for String
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -670,7 +670,7 @@ impl<E> Debug for StringDeserializer<E> {
|
||||
|
||||
/// A deserializer holding a `Cow<str>`.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
pub struct CowStrDeserializer<'a, E> {
|
||||
value: Cow<'a, str>,
|
||||
marker: PhantomData<E>,
|
||||
@@ -687,7 +687,7 @@ impl<'a, E> Clone for CowStrDeserializer<'a, E> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -1006,7 +1006,7 @@ where
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, T, E> IntoDeserializer<'de, E> for Vec<T>
|
||||
where
|
||||
T: IntoDeserializer<'de, E>,
|
||||
@@ -1020,7 +1020,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, T, E> IntoDeserializer<'de, E> for BTreeSet<T>
|
||||
where
|
||||
T: IntoDeserializer<'de, E> + Eq + Ord,
|
||||
@@ -1034,7 +1034,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<'de, T, S, E> IntoDeserializer<'de, E> for HashSet<T, S>
|
||||
where
|
||||
T: IntoDeserializer<'de, E> + Eq + Hash,
|
||||
@@ -1421,7 +1421,7 @@ impl Expected for ExpectedInMap {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl<'de, K, V, E> IntoDeserializer<'de, E> for BTreeMap<K, V>
|
||||
where
|
||||
K: IntoDeserializer<'de, E> + Eq + Ord,
|
||||
@@ -1436,7 +1436,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>
|
||||
where
|
||||
K: IntoDeserializer<'de, E> + Eq + Hash,
|
||||
|
||||
+18
-6
@@ -95,16 +95,17 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Serde types in rustdoc of other crates get linked to here.
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.197")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.210")]
|
||||
// Support using Serde without the standard library!
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// Show which crate feature enables conditionally compiled APIs in documentation.
|
||||
#![cfg_attr(doc_cfg, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]
|
||||
#![cfg_attr(docsrs, allow(internal_features))]
|
||||
// Unstable functionality only if the user asks for it. For tracking and
|
||||
// discussion of these features please refer to this issue:
|
||||
//
|
||||
// https://github.com/serde-rs/serde/issues/812
|
||||
#![cfg_attr(feature = "unstable", feature(error_in_core, never_type))]
|
||||
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||
#![allow(unknown_lints, bare_trait_objects, deprecated)]
|
||||
// Ignored clippy and clippy_pedantic lints
|
||||
#![allow(
|
||||
@@ -118,6 +119,7 @@
|
||||
// integer and float ser/de requires these sorts of casts
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_possible_wrap,
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_sign_loss,
|
||||
// things are often more readable this way
|
||||
clippy::cast_lossless,
|
||||
@@ -236,8 +238,13 @@ mod lib {
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::ffi::CString;
|
||||
|
||||
#[cfg(all(not(no_core_net), not(feature = "std")))]
|
||||
pub use self::core::net;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{error, net};
|
||||
pub use std::net;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::error;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::collections::{HashMap, HashSet};
|
||||
@@ -274,6 +281,9 @@ mod lib {
|
||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
|
||||
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
|
||||
|
||||
#[cfg(not(no_core_num_saturating))]
|
||||
pub use self::core::num::Saturating;
|
||||
}
|
||||
|
||||
// None of this crate's error handling needs the `From::from` error conversion
|
||||
@@ -300,6 +310,8 @@ mod integer128;
|
||||
pub mod de;
|
||||
pub mod ser;
|
||||
|
||||
mod format;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use crate::de::{Deserialize, Deserializer};
|
||||
#[doc(inline)]
|
||||
@@ -313,7 +325,7 @@ pub mod __private;
|
||||
#[path = "de/seed.rs"]
|
||||
mod seed;
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
mod std_error;
|
||||
|
||||
// Re-export #[derive(Serialize, Deserialize)].
|
||||
@@ -326,7 +338,7 @@ extern crate serde_derive;
|
||||
|
||||
/// Derive macro available if serde is built with `features = ["derive"]`.
|
||||
#[cfg(feature = "serde_derive")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
|
||||
pub use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ macro_rules! forward_to_deserialize_any {
|
||||
macro_rules! forward_to_deserialize_any_method {
|
||||
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
|
||||
#[inline]
|
||||
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, Self::Error>
|
||||
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>
|
||||
where
|
||||
$v: $crate::de::Visitor<$l>,
|
||||
{
|
||||
|
||||
+65
-162
@@ -313,6 +313,8 @@ mod content {
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to capture data in [`Content`] from other deserializers.
|
||||
/// Cannot capture externally tagged enums, `i128` and `u128`.
|
||||
struct ContentVisitor<'de> {
|
||||
value: PhantomData<Content<'de>>,
|
||||
}
|
||||
@@ -528,6 +530,8 @@ mod content {
|
||||
Content(Content<'de>),
|
||||
}
|
||||
|
||||
/// Serves as a seed for deserializing a key of internally tagged enum.
|
||||
/// Cannot capture externally tagged enums, `i128` and `u128`.
|
||||
struct TagOrContentVisitor<'de> {
|
||||
name: &'static str,
|
||||
value: PhantomData<TagOrContent<'de>>,
|
||||
@@ -814,6 +818,9 @@ mod content {
|
||||
|
||||
/// Used by generated code to deserialize an internally tagged enum.
|
||||
///
|
||||
/// Captures map or sequence from the original deserializer and searches
|
||||
/// a tag in it (in case of sequence, tag is the first element of sequence).
|
||||
///
|
||||
/// Not public API.
|
||||
pub struct TaggedContentVisitor<T> {
|
||||
tag_name: &'static str,
|
||||
@@ -897,7 +904,9 @@ mod content {
|
||||
|
||||
/// Not public API.
|
||||
pub struct TagOrContentFieldVisitor {
|
||||
/// Name of the tag field of the adjacently tagged enum
|
||||
pub tag: &'static str,
|
||||
/// Name of the content field of the adjacently tagged enum
|
||||
pub content: &'static str,
|
||||
}
|
||||
|
||||
@@ -972,7 +981,9 @@ mod content {
|
||||
|
||||
/// Not public API.
|
||||
pub struct TagContentOtherFieldVisitor {
|
||||
/// Name of the tag field of the adjacently tagged enum
|
||||
pub tag: &'static str,
|
||||
/// Name of the content field of the adjacently tagged enum
|
||||
pub content: &'static str,
|
||||
}
|
||||
|
||||
@@ -1887,10 +1898,19 @@ mod content {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// with_optional_field::*
|
||||
match *self.content {
|
||||
Content::None => visitor.visit_none(),
|
||||
Content::Some(ref v) => visitor.visit_some(ContentRefDeserializer::new(v)),
|
||||
Content::Unit => visitor.visit_unit(),
|
||||
// This case is to support data formats which do not encode an
|
||||
// indication whether a value is optional. An example of such a
|
||||
// format is JSON, and a counterexample is RON. When requesting
|
||||
// `deserialize_any` in JSON, the data format never performs
|
||||
// `Visitor::visit_some` but we still must be able to
|
||||
// deserialize the resulting Content into data structures with
|
||||
// optional fields.
|
||||
_ => visitor.visit_some(self),
|
||||
}
|
||||
}
|
||||
@@ -1920,10 +1940,21 @@ mod content {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_struct
|
||||
match *self.content {
|
||||
Content::Newtype(ref v) => {
|
||||
visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
|
||||
}
|
||||
// This case is to support data formats that encode newtype
|
||||
// structs and their underlying data the same, with no
|
||||
// indication whether a newtype wrapper was present. For example
|
||||
// JSON does this, while RON does not. In RON a newtype's name
|
||||
// is included in the serialized representation and it knows to
|
||||
// call `Visitor::visit_newtype_struct` from `deserialize_any`.
|
||||
// JSON's `deserialize_any` never calls `visit_newtype_struct`
|
||||
// but in this code we still must be able to deserialize the
|
||||
// resulting Content into newtypes.
|
||||
_ => visitor.visit_newtype_struct(self),
|
||||
}
|
||||
}
|
||||
@@ -2128,6 +2159,10 @@ mod content {
|
||||
fn unit_variant(self) -> Result<(), E> {
|
||||
match self.value {
|
||||
Some(value) => de::Deserialize::deserialize(ContentRefDeserializer::new(value)),
|
||||
// Covered by tests/test_annotations.rs
|
||||
// test_partially_untagged_adjacently_tagged_enum
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_enum::unit
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -2137,6 +2172,11 @@ mod content {
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
match self.value {
|
||||
// Covered by tests/test_annotations.rs
|
||||
// test_partially_untagged_enum_desugared
|
||||
// test_partially_untagged_enum_generic
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_enum::newtype
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
None => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
@@ -2150,9 +2190,13 @@ mod content {
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
match self.value {
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
// Covered by tests/test_annotations.rs
|
||||
// test_partially_untagged_enum
|
||||
// test_partially_untagged_enum_desugared
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_enum::tuple0
|
||||
// newtype_enum::tuple2
|
||||
Some(Content::Seq(v)) => visit_content_seq_ref(v, visitor),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"tuple variant",
|
||||
@@ -2173,12 +2217,13 @@ mod content {
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
match self.value {
|
||||
Some(Content::Map(v)) => {
|
||||
de::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_enum::struct_from_map
|
||||
Some(Content::Map(v)) => visit_content_map_ref(v, visitor),
|
||||
// Covered by tests/test_enum_untagged.rs
|
||||
// newtype_enum::struct_from_seq
|
||||
// newtype_enum::empty_struct_from_seq
|
||||
Some(Content::Seq(v)) => visit_content_seq_ref(v, visitor),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"struct variant",
|
||||
@@ -2191,158 +2236,6 @@ mod content {
|
||||
}
|
||||
}
|
||||
|
||||
struct SeqRefDeserializer<'a, 'de: 'a, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
iter: <&'a [Content<'de>] as IntoIterator>::IntoIter,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, 'de, E> SeqRefDeserializer<'a, 'de, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
fn new(slice: &'a [Content<'de>]) -> Self {
|
||||
SeqRefDeserializer {
|
||||
iter: slice.iter(),
|
||||
err: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for SeqRefDeserializer<'a, '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 = tri!(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, 'a, E> de::SeqAccess<'de> for SeqRefDeserializer<'a, '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(ContentRefDeserializer::new(value))
|
||||
.map(Some),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> Option<usize> {
|
||||
size_hint::from_bounds(&self.iter)
|
||||
}
|
||||
}
|
||||
|
||||
struct MapRefDeserializer<'a, 'de: 'a, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
iter: <&'a [(Content<'de>, Content<'de>)] as IntoIterator>::IntoIter,
|
||||
value: Option<&'a Content<'de>>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, 'de, E> MapRefDeserializer<'a, 'de, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
fn new(map: &'a [(Content<'de>, Content<'de>)]) -> Self {
|
||||
MapRefDeserializer {
|
||||
iter: map.iter(),
|
||||
value: None,
|
||||
err: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, E> de::MapAccess<'de> for MapRefDeserializer<'a, '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(ContentRefDeserializer::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(ContentRefDeserializer::new(value)),
|
||||
None => Err(de::Error::custom("value is missing")),
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> Option<usize> {
|
||||
size_hint::from_bounds(&self.iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for MapRefDeserializer<'a, '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
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, E> de::IntoDeserializer<'de, E> for ContentDeserializer<'de, E>
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -2703,6 +2596,17 @@ where
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn deserialize_unit_struct<V>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
visitor: V,
|
||||
) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
@@ -2727,7 +2631,6 @@ where
|
||||
deserialize_string()
|
||||
deserialize_bytes()
|
||||
deserialize_byte_buf()
|
||||
deserialize_unit_struct(&'static str)
|
||||
deserialize_seq()
|
||||
deserialize_tuple(usize)
|
||||
deserialize_tuple_struct(&'static str, usize)
|
||||
|
||||
@@ -56,7 +56,10 @@ macro_rules! __serialize_unimplemented {
|
||||
#[macro_export]
|
||||
macro_rules! __serialize_unimplemented_method {
|
||||
($func:ident $(<$t:ident>)* ($($arg:ty),*) -> $ret:ident) => {
|
||||
fn $func $(<$t: ?Sized + $crate::Serialize>)* (self $(, _: $arg)*) -> $crate::__private::Result<Self::$ret, Self::Error> {
|
||||
fn $func $(<$t>)* (self $(, _: $arg)*) -> $crate::__private::Result<Self::$ret, Self::Error>
|
||||
where
|
||||
$($t: ?Sized + $crate::Serialize,)*
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
};
|
||||
|
||||
+58
-83
@@ -51,8 +51,6 @@ enum Unsupported {
|
||||
String,
|
||||
ByteArray,
|
||||
Optional,
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
UnitStruct,
|
||||
Sequence,
|
||||
Tuple,
|
||||
TupleStruct,
|
||||
@@ -69,8 +67,6 @@ impl Display for Unsupported {
|
||||
Unsupported::String => formatter.write_str("a string"),
|
||||
Unsupported::ByteArray => formatter.write_str("a byte array"),
|
||||
Unsupported::Optional => formatter.write_str("an optional"),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Unsupported::UnitStruct => formatter.write_str("unit struct"),
|
||||
Unsupported::Sequence => formatter.write_str("a sequence"),
|
||||
Unsupported::Tuple => formatter.write_str("a tuple"),
|
||||
Unsupported::TupleStruct => formatter.write_str("a tuple struct"),
|
||||
@@ -174,9 +170,9 @@ where
|
||||
Err(self.bad_type(Unsupported::Optional))
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn serialize_some<T>(self, _: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Err(self.bad_type(Unsupported::Optional))
|
||||
}
|
||||
@@ -205,18 +201,18 @@ where
|
||||
map.end()
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
_: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
_: &'static str,
|
||||
_: u32,
|
||||
@@ -224,7 +220,7 @@ where
|
||||
inner_value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let mut map = tri!(self.delegate.serialize_map(Some(2)));
|
||||
tri!(map.serialize_entry(self.tag, self.variant_name));
|
||||
@@ -327,9 +323,9 @@ where
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))]
|
||||
fn collect_str<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn collect_str<T>(self, _: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Display,
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
Err(self.bad_type(Unsupported::String))
|
||||
}
|
||||
@@ -364,9 +360,9 @@ mod content {
|
||||
type Ok = M::Ok;
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), M::Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), M::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push(value);
|
||||
@@ -404,13 +400,9 @@ mod content {
|
||||
type Ok = M::Ok;
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(
|
||||
&mut self,
|
||||
key: &'static str,
|
||||
value: &T,
|
||||
) -> Result<(), M::Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), M::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push((key, value));
|
||||
@@ -635,9 +627,9 @@ mod content {
|
||||
Ok(Content::None)
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Content, E>
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Content, E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Ok(Content::Some(Box::new(tri!(value.serialize(self)))))
|
||||
}
|
||||
@@ -659,13 +651,9 @@ mod content {
|
||||
Ok(Content::UnitVariant(name, variant_index, variant))
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(
|
||||
self,
|
||||
name: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Content, E>
|
||||
fn serialize_newtype_struct<T>(self, name: &'static str, value: &T) -> Result<Content, E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Ok(Content::NewtypeStruct(
|
||||
name,
|
||||
@@ -673,7 +661,7 @@ mod content {
|
||||
))
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
@@ -681,7 +669,7 @@ mod content {
|
||||
value: &T,
|
||||
) -> Result<Content, E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Ok(Content::NewtypeVariant(
|
||||
name,
|
||||
@@ -782,9 +770,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.elements.push(value);
|
||||
@@ -808,9 +796,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.elements.push(value);
|
||||
@@ -835,9 +823,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push(value);
|
||||
@@ -864,9 +852,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push(value);
|
||||
@@ -896,18 +884,18 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), E>
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
|
||||
self.key = Some(key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let key = self
|
||||
.key
|
||||
@@ -922,10 +910,10 @@ mod content {
|
||||
Ok(Content::Map(self.entries))
|
||||
}
|
||||
|
||||
fn serialize_entry<K: ?Sized, V: ?Sized>(&mut self, key: &K, value: &V) -> Result<(), E>
|
||||
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), E>
|
||||
where
|
||||
K: Serialize,
|
||||
V: Serialize,
|
||||
K: ?Sized + Serialize,
|
||||
V: ?Sized + Serialize,
|
||||
{
|
||||
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
@@ -947,9 +935,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push((key, value));
|
||||
@@ -976,9 +964,9 @@ mod content {
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), E>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push((key, value));
|
||||
@@ -1088,9 +1076,9 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
value.serialize(self)
|
||||
}
|
||||
@@ -1100,7 +1088,7 @@ where
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||
Err(Self::bad_type(Unsupported::UnitStruct))
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_unit_variant(
|
||||
@@ -1112,18 +1100,18 @@ where
|
||||
Err(Self::bad_type(Unsupported::Enum))
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
_: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
_: &'static str,
|
||||
_: u32,
|
||||
@@ -1131,10 +1119,9 @@ where
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
tri!(self.0.serialize_key(variant));
|
||||
self.0.serialize_value(value)
|
||||
self.0.serialize_entry(variant, value)
|
||||
}
|
||||
|
||||
fn serialize_seq(self, _: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
@@ -1202,28 +1189,24 @@ where
|
||||
type Ok = ();
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.0.serialize_key(key)
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.0.serialize_value(value)
|
||||
}
|
||||
|
||||
fn serialize_entry<K: ?Sized, V: ?Sized>(
|
||||
&mut self,
|
||||
key: &K,
|
||||
value: &V,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
|
||||
where
|
||||
K: Serialize,
|
||||
V: Serialize,
|
||||
K: ?Sized + Serialize,
|
||||
V: ?Sized + Serialize,
|
||||
{
|
||||
self.0.serialize_entry(key, value)
|
||||
}
|
||||
@@ -1244,13 +1227,9 @@ where
|
||||
type Ok = ();
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(
|
||||
&mut self,
|
||||
key: &'static str,
|
||||
value: &T,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.0.serialize_entry(key, value)
|
||||
}
|
||||
@@ -1289,9 +1268,9 @@ where
|
||||
type Ok = ();
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push(value);
|
||||
@@ -1335,13 +1314,9 @@ where
|
||||
type Ok = ();
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(
|
||||
&mut self,
|
||||
key: &'static str,
|
||||
value: &T,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push((key, value));
|
||||
|
||||
@@ -74,9 +74,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
Display::fmt(variant, self)
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> fmt::Result
|
||||
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Serialize::serialize(value, self)
|
||||
}
|
||||
@@ -89,9 +89,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized>(self, _value: &T) -> fmt::Result
|
||||
fn serialize_some<T>(self, _value: &T) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Err(fmt::Error)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
@@ -108,7 +108,7 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
_value: &T,
|
||||
) -> fmt::Result
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
Err(fmt::Error)
|
||||
}
|
||||
@@ -161,9 +161,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> fmt::Result
|
||||
fn collect_str<T>(self, value: &T) -> fmt::Result
|
||||
where
|
||||
T: Display,
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
Display::fmt(value, self)
|
||||
}
|
||||
|
||||
+104
-85
@@ -48,7 +48,7 @@ impl Serialize for str {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl Serialize for String {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -71,7 +71,7 @@ impl<'a> Serialize for fmt::Arguments<'a> {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_cstr)))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Serialize for CStr {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -83,7 +83,7 @@ impl Serialize for CStr {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
impl Serialize for CString {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -114,7 +114,10 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
impl<T: ?Sized> Serialize for PhantomData<T> {
|
||||
impl<T> Serialize for PhantomData<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
{
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -229,37 +232,37 @@ macro_rules! seq_impl {
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BinaryHeap<T: Ord>
|
||||
}
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BTreeSet<T: Ord>
|
||||
}
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
HashSet<T: Eq + Hash, H: BuildHasher>
|
||||
}
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
LinkedList<T>
|
||||
}
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
Vec<T>
|
||||
}
|
||||
|
||||
seq_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
VecDeque<T>
|
||||
}
|
||||
|
||||
@@ -368,7 +371,7 @@ impl Serialize for () {
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||
impl Serialize for ! {
|
||||
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -383,28 +386,46 @@ impl Serialize for ! {
|
||||
macro_rules! tuple_impls {
|
||||
($($len:expr => ($($n:tt $name:ident)+))+) => {
|
||||
$(
|
||||
#[cfg_attr(docsrs, doc(hidden))]
|
||||
impl<$($name),+> Serialize for ($($name,)+)
|
||||
where
|
||||
$($name: Serialize,)+
|
||||
{
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut tuple = tri!(serializer.serialize_tuple($len));
|
||||
$(
|
||||
tri!(tuple.serialize_element(&self.$n));
|
||||
)+
|
||||
tuple.end()
|
||||
}
|
||||
tuple_impl_body!($len => ($($n)+));
|
||||
}
|
||||
)+
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! tuple_impl_body {
|
||||
($len:expr => ($($n:tt)+)) => {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut tuple = tri!(serializer.serialize_tuple($len));
|
||||
$(
|
||||
tri!(tuple.serialize_element(&self.$n));
|
||||
)+
|
||||
tuple.end()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg_attr(docsrs, doc(fake_variadic))]
|
||||
#[cfg_attr(
|
||||
docsrs,
|
||||
doc = "This trait is implemented for tuples up to 16 items long."
|
||||
)]
|
||||
impl<T> Serialize for (T,)
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
tuple_impl_body!(1 => (0));
|
||||
}
|
||||
|
||||
tuple_impls! {
|
||||
1 => (0 T0)
|
||||
2 => (0 T0 1 T1)
|
||||
3 => (0 T0 1 T1 2 T2)
|
||||
4 => (0 T0 1 T1 2 T2 3 T3)
|
||||
@@ -473,13 +494,13 @@ macro_rules! map_impl {
|
||||
|
||||
map_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
BTreeMap<K: Ord, V>
|
||||
}
|
||||
|
||||
map_impl! {
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
HashMap<K: Eq + Hash, V, H: BuildHasher>
|
||||
}
|
||||
|
||||
@@ -504,17 +525,17 @@ macro_rules! deref_impl {
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
<'a, T: ?Sized> Serialize for &'a T where T: Serialize
|
||||
<'a, T> Serialize for &'a T where T: ?Sized + Serialize
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize
|
||||
<'a, T> Serialize for &'a mut T where T: ?Sized + Serialize
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
<T: ?Sized> Serialize for Box<T> where T: Serialize
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
<T> Serialize for Box<T> where T: ?Sized + Serialize
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
@@ -527,8 +548,8 @@ deref_impl! {
|
||||
///
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
<T: ?Sized> Serialize for Rc<T> where T: Serialize
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
<T> Serialize for Rc<T> where T: ?Sized + Serialize
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
@@ -541,14 +562,14 @@ deref_impl! {
|
||||
///
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
<T: ?Sized> Serialize for Arc<T> where T: Serialize
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
|
||||
<T> Serialize for Arc<T> where T: ?Sized + Serialize
|
||||
}
|
||||
|
||||
deref_impl! {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
||||
<'a, T> Serialize for Cow<'a, T> where T: ?Sized + Serialize + ToOwned
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -558,12 +579,12 @@ deref_impl! {
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(
|
||||
doc_cfg,
|
||||
docsrs,
|
||||
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
|
||||
)]
|
||||
impl<T: ?Sized> Serialize for RcWeak<T>
|
||||
impl<T> Serialize for RcWeak<T>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -578,12 +599,12 @@ where
|
||||
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||
#[cfg_attr(
|
||||
doc_cfg,
|
||||
docsrs,
|
||||
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
|
||||
)]
|
||||
impl<T: ?Sized> Serialize for ArcWeak<T>
|
||||
impl<T> Serialize for ArcWeak<T>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -641,9 +662,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> Serialize for RefCell<T>
|
||||
impl<T> Serialize for RefCell<T>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -657,10 +678,10 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
impl<T: ?Sized> Serialize for Mutex<T>
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<T> Serialize for Mutex<T>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -674,10 +695,10 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
impl<T: ?Sized> Serialize for RwLock<T>
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl<T> Serialize for RwLock<T>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -728,7 +749,7 @@ impl Serialize for Duration {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Serialize for SystemTime {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -752,28 +773,17 @@ impl Serialize for SystemTime {
|
||||
/// statically known to never have more than a constant `MAX_LEN` bytes.
|
||||
///
|
||||
/// Panics if the `Display` impl tries to write more than `MAX_LEN` bytes.
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
macro_rules! serialize_display_bounded_length {
|
||||
($value:expr, $max:expr, $serializer:expr) => {{
|
||||
let mut buffer = [0u8; $max];
|
||||
let remaining_len = {
|
||||
let mut remaining = &mut buffer[..];
|
||||
write!(remaining, "{}", $value).unwrap();
|
||||
remaining.len()
|
||||
};
|
||||
let written_len = buffer.len() - remaining_len;
|
||||
let written = &buffer[..written_len];
|
||||
|
||||
// write! only provides fmt::Formatter to Display implementations, which
|
||||
// has methods write_str and write_char but no method to write arbitrary
|
||||
// bytes. Therefore `written` must be valid UTF-8.
|
||||
let written_str = str::from_utf8(written).expect("must be valid UTF-8");
|
||||
$serializer.serialize_str(written_str)
|
||||
let mut writer = crate::format::Buf::new(&mut buffer);
|
||||
write!(&mut writer, "{}", $value).unwrap();
|
||||
$serializer.serialize_str(writer.as_str())
|
||||
}};
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::IpAddr {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -797,7 +807,7 @@ impl Serialize for net::IpAddr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
const DEC_DIGITS_LUT: &[u8] = b"\
|
||||
0001020304050607080910111213141516171819\
|
||||
2021222324252627282930313233343536373839\
|
||||
@@ -805,7 +815,7 @@ const DEC_DIGITS_LUT: &[u8] = b"\
|
||||
6061626364656667686970717273747576777879\
|
||||
8081828384858687888990919293949596979899";
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
#[inline]
|
||||
fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
|
||||
if n >= 100 {
|
||||
@@ -826,7 +836,7 @@ fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
#[test]
|
||||
fn test_format_u8() {
|
||||
let mut i = 0u8;
|
||||
@@ -843,8 +853,7 @@ fn test_format_u8() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::Ipv4Addr {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -868,8 +877,7 @@ impl Serialize for net::Ipv4Addr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::Ipv6Addr {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -885,8 +893,7 @@ impl Serialize for net::Ipv6Addr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::SocketAddr {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -910,8 +917,7 @@ impl Serialize for net::SocketAddr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::SocketAddrV4 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -927,8 +933,7 @@ impl Serialize for net::SocketAddrV4 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||
impl Serialize for net::SocketAddrV6 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -950,7 +955,7 @@ impl Serialize for net::SocketAddrV6 {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Serialize for Path {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -964,7 +969,7 @@ impl Serialize for Path {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl Serialize for PathBuf {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -975,7 +980,7 @@ impl Serialize for PathBuf {
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
impl Serialize for OsStr {
|
||||
#[cfg(unix)]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -998,7 +1003,7 @@ impl Serialize for OsStr {
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
|
||||
impl Serialize for OsString {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -1023,6 +1028,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(no_core_num_saturating))]
|
||||
impl<T> Serialize for Saturating<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for Reverse<T>
|
||||
where
|
||||
T: Serialize,
|
||||
@@ -1043,7 +1062,7 @@ macro_rules! atomic_impl {
|
||||
($($ty:ident $size:expr)*) => {
|
||||
$(
|
||||
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
|
||||
impl Serialize for $ty {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
||||
+16
-16
@@ -72,9 +72,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
@@ -92,9 +92,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
@@ -112,9 +112,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
@@ -132,9 +132,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
@@ -152,17 +152,17 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Error>
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
match self.void {}
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = value;
|
||||
match self.void {}
|
||||
@@ -180,9 +180,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
let _ = value;
|
||||
@@ -201,9 +201,9 @@ where
|
||||
type Ok = Ok;
|
||||
type Error = Error;
|
||||
|
||||
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
|
||||
where
|
||||
T: Serialize,
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let _ = key;
|
||||
let _ = value;
|
||||
|
||||
+46
-44
@@ -115,10 +115,10 @@ mod impossible;
|
||||
|
||||
pub use self::impossible::Impossible;
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::std_error::Error as StdError;
|
||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
||||
#[cfg(not(any(feature = "std", no_core_error)))]
|
||||
#[doc(no_inline)]
|
||||
pub use core::error::Error as StdError;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -215,6 +215,13 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
||||
/// [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
||||
/// [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||
/// [derive section of the manual]: https://serde.rs/derive.html
|
||||
#[cfg_attr(
|
||||
not(no_diagnostic_namespace),
|
||||
diagnostic::on_unimplemented(
|
||||
note = "for local types consider adding `#[derive(serde::Serialize)]` to your `{Self}` type",
|
||||
note = "for types from other crates check whether the crate offers a `serde` feature flag",
|
||||
)
|
||||
)]
|
||||
pub trait Serialize {
|
||||
/// Serialize this value into the given Serde serializer.
|
||||
///
|
||||
@@ -796,9 +803,9 @@ pub trait Serializer: Sized {
|
||||
/// ```
|
||||
///
|
||||
/// [`Some(T)`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some
|
||||
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Serialize a `()` value.
|
||||
///
|
||||
@@ -891,13 +898,13 @@ pub trait Serializer: Sized {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn serialize_newtype_struct<T: ?Sized>(
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Serialize a newtype variant like `E::N` in `enum E { N(u8) }`.
|
||||
///
|
||||
@@ -925,7 +932,7 @@ pub trait Serializer: Sized {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
@@ -933,7 +940,7 @@ pub trait Serializer: Sized {
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Begin to serialize a variably sized sequence. This call must be
|
||||
/// followed by zero or more calls to `serialize_element`, then a call to
|
||||
@@ -1170,7 +1177,8 @@ pub trait Serializer: Sized {
|
||||
/// then a call to `end`.
|
||||
///
|
||||
/// The `name` is the name of the struct and the `len` is the number of
|
||||
/// data fields that will be serialized.
|
||||
/// data fields that will be serialized. `len` does not include fields
|
||||
/// which are skipped with [`SerializeStruct::skip_field`].
|
||||
///
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
@@ -1207,6 +1215,8 @@ pub trait Serializer: Sized {
|
||||
/// The `name` is the name of the enum, the `variant_index` is the index of
|
||||
/// this variant within the enum, the `variant` is the name of the variant,
|
||||
/// and the `len` is the number of data fields that will be serialized.
|
||||
/// `len` does not include fields which are skipped with
|
||||
/// [`SerializeStructVariant::skip_field`].
|
||||
///
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||
@@ -1346,9 +1356,9 @@ pub trait Serializer: Sized {
|
||||
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
|
||||
/// [`serialize_str`]: #tymethod.serialize_str
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Display,
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
self.serialize_str(&value.to_string())
|
||||
}
|
||||
@@ -1379,9 +1389,9 @@ pub trait Serializer: Sized {
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))]
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Display;
|
||||
T: ?Sized + Display;
|
||||
|
||||
/// Determine whether `Serialize` implementations should serialize in
|
||||
/// human-readable form.
|
||||
@@ -1493,9 +1503,9 @@ pub trait SerializeSeq {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a sequence element.
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Finish serializing a sequence.
|
||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||
@@ -1593,9 +1603,9 @@ pub trait SerializeTuple {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a tuple element.
|
||||
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Finish serializing a tuple.
|
||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||
@@ -1638,9 +1648,9 @@ pub trait SerializeTupleStruct {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a tuple struct field.
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Finish serializing a tuple struct.
|
||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||
@@ -1696,9 +1706,9 @@ pub trait SerializeTupleVariant {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a tuple variant field.
|
||||
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Finish serializing a tuple variant.
|
||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||
@@ -1767,9 +1777,9 @@ pub trait SerializeMap {
|
||||
/// `serialize_entry` instead as it may be implemented more efficiently in
|
||||
/// some formats compared to a pair of calls to `serialize_key` and
|
||||
/// `serialize_value`.
|
||||
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Serialize a map value.
|
||||
///
|
||||
@@ -1777,9 +1787,9 @@ pub trait SerializeMap {
|
||||
///
|
||||
/// Calling `serialize_value` before `serialize_key` is incorrect and is
|
||||
/// allowed to panic or produce bogus results.
|
||||
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Serialize a map entry consisting of a key and a value.
|
||||
///
|
||||
@@ -1798,14 +1808,10 @@ pub trait SerializeMap {
|
||||
/// [`Serialize`]: ../trait.Serialize.html
|
||||
/// [`serialize_key`]: #tymethod.serialize_key
|
||||
/// [`serialize_value`]: #tymethod.serialize_value
|
||||
fn serialize_entry<K: ?Sized, V: ?Sized>(
|
||||
&mut self,
|
||||
key: &K,
|
||||
value: &V,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
|
||||
where
|
||||
K: Serialize,
|
||||
V: Serialize,
|
||||
K: ?Sized + Serialize,
|
||||
V: ?Sized + Serialize,
|
||||
{
|
||||
tri!(self.serialize_key(key));
|
||||
self.serialize_value(value)
|
||||
@@ -1856,15 +1862,13 @@ pub trait SerializeStruct {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a struct field.
|
||||
fn serialize_field<T: ?Sized>(
|
||||
&mut self,
|
||||
key: &'static str,
|
||||
value: &T,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Indicate that a struct field has been skipped.
|
||||
///
|
||||
/// The default implementation does nothing.
|
||||
#[inline]
|
||||
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
|
||||
let _ = key;
|
||||
@@ -1922,15 +1926,13 @@ pub trait SerializeStructVariant {
|
||||
type Error: Error;
|
||||
|
||||
/// Serialize a struct variant field.
|
||||
fn serialize_field<T: ?Sized>(
|
||||
&mut self,
|
||||
key: &'static str,
|
||||
value: &T,
|
||||
) -> Result<(), Self::Error>
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: Serialize;
|
||||
T: ?Sized + Serialize;
|
||||
|
||||
/// Indicate that a struct variant field has been skipped.
|
||||
///
|
||||
/// The default implementation does nothing.
|
||||
#[inline]
|
||||
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
|
||||
let _ = key;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.197"
|
||||
version = "1.0.210"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
categories = ["no-std", "no-std::no-alloc"]
|
||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||
documentation = "https://serde.rs/derive.html"
|
||||
edition = "2015"
|
||||
exclude = ["build.rs"]
|
||||
homepage = "https://serde.rs"
|
||||
keywords = ["serde", "serialization", "no_std", "derive"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
// Warning: build.rs is not published to crates.io.
|
||||
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rustc-cfg=check_cfg");
|
||||
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
|
||||
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
|
||||
}
|
||||
+52
-28
@@ -461,7 +461,10 @@ fn deserialize_tuple(
|
||||
cattrs: &attr::Container,
|
||||
form: TupleForm,
|
||||
) -> Fragment {
|
||||
assert!(!cattrs.has_flatten());
|
||||
assert!(
|
||||
!has_flatten(fields),
|
||||
"tuples and tuple variants cannot have flatten fields"
|
||||
);
|
||||
|
||||
let field_count = fields
|
||||
.iter()
|
||||
@@ -579,7 +582,10 @@ fn deserialize_tuple_in_place(
|
||||
fields: &[Field],
|
||||
cattrs: &attr::Container,
|
||||
) -> Fragment {
|
||||
assert!(!cattrs.has_flatten());
|
||||
assert!(
|
||||
!has_flatten(fields),
|
||||
"tuples and tuple variants cannot have flatten fields"
|
||||
);
|
||||
|
||||
let field_count = fields
|
||||
.iter()
|
||||
@@ -958,13 +964,15 @@ fn deserialize_struct(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||
|
||||
let has_flatten = has_flatten(fields);
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, has_flatten);
|
||||
|
||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||
// structs that only have a map representation.
|
||||
let visit_seq = match form {
|
||||
StructForm::Untagged(..) => None,
|
||||
_ if cattrs.has_flatten() => None,
|
||||
_ if has_flatten => None,
|
||||
_ => {
|
||||
let mut_seq = if field_names_idents.is_empty() {
|
||||
quote!(_)
|
||||
@@ -987,10 +995,16 @@ fn deserialize_struct(
|
||||
})
|
||||
}
|
||||
};
|
||||
let visit_map = Stmts(deserialize_map(&type_path, params, fields, cattrs));
|
||||
let visit_map = Stmts(deserialize_map(
|
||||
&type_path,
|
||||
params,
|
||||
fields,
|
||||
cattrs,
|
||||
has_flatten,
|
||||
));
|
||||
|
||||
let visitor_seed = match form {
|
||||
StructForm::ExternallyTagged(..) if cattrs.has_flatten() => Some(quote! {
|
||||
StructForm::ExternallyTagged(..) if has_flatten => Some(quote! {
|
||||
impl #de_impl_generics _serde::de::DeserializeSeed<#delife> for __Visitor #de_ty_generics #where_clause {
|
||||
type Value = #this_type #ty_generics;
|
||||
|
||||
@@ -1005,7 +1019,7 @@ fn deserialize_struct(
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let fields_stmt = if cattrs.has_flatten() {
|
||||
let fields_stmt = if has_flatten {
|
||||
None
|
||||
} else {
|
||||
let field_names = field_names_idents
|
||||
@@ -1025,7 +1039,7 @@ fn deserialize_struct(
|
||||
}
|
||||
};
|
||||
let dispatch = match form {
|
||||
StructForm::Struct if cattrs.has_flatten() => quote! {
|
||||
StructForm::Struct if has_flatten => quote! {
|
||||
_serde::Deserializer::deserialize_map(__deserializer, #visitor_expr)
|
||||
},
|
||||
StructForm::Struct => {
|
||||
@@ -1034,7 +1048,7 @@ fn deserialize_struct(
|
||||
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS, #visitor_expr)
|
||||
}
|
||||
}
|
||||
StructForm::ExternallyTagged(_) if cattrs.has_flatten() => quote! {
|
||||
StructForm::ExternallyTagged(_) if has_flatten => quote! {
|
||||
_serde::de::VariantAccess::newtype_variant_seed(__variant, #visitor_expr)
|
||||
},
|
||||
StructForm::ExternallyTagged(_) => quote! {
|
||||
@@ -1091,7 +1105,7 @@ fn deserialize_struct_in_place(
|
||||
) -> Option<Fragment> {
|
||||
// for now we do not support in_place deserialization for structs that
|
||||
// are represented as map.
|
||||
if cattrs.has_flatten() {
|
||||
if has_flatten(fields) {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -1116,7 +1130,7 @@ fn deserialize_struct_in_place(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, false);
|
||||
|
||||
let mut_seq = if field_names_idents.is_empty() {
|
||||
quote!(_)
|
||||
@@ -1210,10 +1224,7 @@ fn deserialize_homogeneous_enum(
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_enum_variant_enum(
|
||||
variants: &[Variant],
|
||||
cattrs: &attr::Container,
|
||||
) -> (TokenStream, Stmts) {
|
||||
fn prepare_enum_variant_enum(variants: &[Variant]) -> (TokenStream, Stmts) {
|
||||
let mut deserialized_variants = variants
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -1247,7 +1258,7 @@ fn prepare_enum_variant_enum(
|
||||
|
||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
||||
&variant_names_idents,
|
||||
cattrs,
|
||||
false, // variant identifiers do not depend on the presence of flatten fields
|
||||
true,
|
||||
None,
|
||||
fallthrough,
|
||||
@@ -1270,7 +1281,7 @@ fn deserialize_externally_tagged_enum(
|
||||
let expecting = format!("enum {}", params.type_name());
|
||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants);
|
||||
|
||||
// Match arms to extract a variant from a string
|
||||
let variant_arms = variants
|
||||
@@ -1355,7 +1366,7 @@ fn deserialize_internally_tagged_enum(
|
||||
cattrs: &attr::Container,
|
||||
tag: &str,
|
||||
) -> Fragment {
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants);
|
||||
|
||||
// Match arms to extract a variant from a string
|
||||
let variant_arms = variants
|
||||
@@ -1409,7 +1420,7 @@ fn deserialize_adjacently_tagged_enum(
|
||||
split_with_de_lifetime(params);
|
||||
let delife = params.borrowed.de_lifetime();
|
||||
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants);
|
||||
|
||||
let variant_arms: &Vec<_> = &variants
|
||||
.iter()
|
||||
@@ -1985,7 +1996,7 @@ fn deserialize_untagged_newtype_variant(
|
||||
|
||||
fn deserialize_generated_identifier(
|
||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||
cattrs: &attr::Container,
|
||||
has_flatten: bool,
|
||||
is_variant: bool,
|
||||
ignore_variant: Option<TokenStream>,
|
||||
fallthrough: Option<TokenStream>,
|
||||
@@ -1999,11 +2010,11 @@ fn deserialize_generated_identifier(
|
||||
is_variant,
|
||||
fallthrough,
|
||||
None,
|
||||
!is_variant && cattrs.has_flatten(),
|
||||
!is_variant && has_flatten,
|
||||
None,
|
||||
));
|
||||
|
||||
let lifetime = if !is_variant && cattrs.has_flatten() {
|
||||
let lifetime = if !is_variant && has_flatten {
|
||||
Some(quote!(<'de>))
|
||||
} else {
|
||||
None
|
||||
@@ -2043,8 +2054,9 @@ fn deserialize_generated_identifier(
|
||||
fn deserialize_field_identifier(
|
||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||
cattrs: &attr::Container,
|
||||
has_flatten: bool,
|
||||
) -> Stmts {
|
||||
let (ignore_variant, fallthrough) = if cattrs.has_flatten() {
|
||||
let (ignore_variant, fallthrough) = if has_flatten {
|
||||
let ignore_variant = quote!(__other(_serde::__private::de::Content<'de>),);
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__other(__value)));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
@@ -2058,7 +2070,7 @@ fn deserialize_field_identifier(
|
||||
|
||||
Stmts(deserialize_generated_identifier(
|
||||
fields,
|
||||
cattrs,
|
||||
has_flatten,
|
||||
false,
|
||||
ignore_variant,
|
||||
fallthrough,
|
||||
@@ -2460,6 +2472,7 @@ fn deserialize_map(
|
||||
params: &Parameters,
|
||||
fields: &[Field],
|
||||
cattrs: &attr::Container,
|
||||
has_flatten: bool,
|
||||
) -> Fragment {
|
||||
// Create the field names for the fields.
|
||||
let fields_names: Vec<_> = fields
|
||||
@@ -2480,7 +2493,7 @@ fn deserialize_map(
|
||||
});
|
||||
|
||||
// Collect contents for flatten fields into a buffer
|
||||
let let_collect = if cattrs.has_flatten() {
|
||||
let let_collect = if has_flatten {
|
||||
Some(quote! {
|
||||
let mut __collect = _serde::__private::Vec::<_serde::__private::Option<(
|
||||
_serde::__private::de::Content,
|
||||
@@ -2532,7 +2545,7 @@ fn deserialize_map(
|
||||
});
|
||||
|
||||
// Visit ignored values to consume them
|
||||
let ignored_arm = if cattrs.has_flatten() {
|
||||
let ignored_arm = if has_flatten {
|
||||
Some(quote! {
|
||||
__Field::__other(__name) => {
|
||||
__collect.push(_serde::__private::Some((
|
||||
@@ -2602,7 +2615,7 @@ fn deserialize_map(
|
||||
}
|
||||
});
|
||||
|
||||
let collected_deny_unknown_fields = if cattrs.has_flatten() && cattrs.deny_unknown_fields() {
|
||||
let collected_deny_unknown_fields = if has_flatten && cattrs.deny_unknown_fields() {
|
||||
Some(quote! {
|
||||
if let _serde::__private::Some(_serde::__private::Some((__key, _))) =
|
||||
__collect.into_iter().filter(_serde::__private::Option::is_some).next()
|
||||
@@ -2678,7 +2691,10 @@ fn deserialize_map_in_place(
|
||||
fields: &[Field],
|
||||
cattrs: &attr::Container,
|
||||
) -> Fragment {
|
||||
assert!(!cattrs.has_flatten());
|
||||
assert!(
|
||||
!has_flatten(fields),
|
||||
"inplace deserialization of maps does not support flatten fields"
|
||||
);
|
||||
|
||||
// Create the field names for the fields.
|
||||
let fields_names: Vec<_> = fields
|
||||
@@ -3011,6 +3027,14 @@ fn effective_style(variant: &Variant) -> Style {
|
||||
}
|
||||
}
|
||||
|
||||
/// True if there is any field with a `#[serde(flatten)]` attribute, other than
|
||||
/// fields which are skipped.
|
||||
fn has_flatten(fields: &[Field]) -> bool {
|
||||
fields
|
||||
.iter()
|
||||
.any(|field| field.attrs.flatten() && !field.attrs.skip_deserializing())
|
||||
}
|
||||
|
||||
struct DeImplGenerics<'a>(&'a Parameters);
|
||||
#[cfg(feature = "deserialize_in_place")]
|
||||
struct InPlaceImplGenerics<'a>(&'a Parameters);
|
||||
|
||||
@@ -63,7 +63,7 @@ impl<'a> Container<'a> {
|
||||
item: &'a syn::DeriveInput,
|
||||
derive: Derive,
|
||||
) -> Option<Container<'a>> {
|
||||
let mut attrs = attr::Container::from_ast(cx, item);
|
||||
let attrs = attr::Container::from_ast(cx, item);
|
||||
|
||||
let mut data = match &item.data {
|
||||
syn::Data::Enum(data) => Data::Enum(enum_from_ast(cx, &data.variants, attrs.default())),
|
||||
@@ -77,15 +77,11 @@ impl<'a> Container<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
let mut has_flatten = false;
|
||||
match &mut data {
|
||||
Data::Enum(variants) => {
|
||||
for variant in variants {
|
||||
variant.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||
for field in &mut variant.fields {
|
||||
if field.attrs.flatten() {
|
||||
has_flatten = true;
|
||||
}
|
||||
field.attrs.rename_by_rules(
|
||||
variant
|
||||
.attrs
|
||||
@@ -97,18 +93,11 @@ impl<'a> Container<'a> {
|
||||
}
|
||||
Data::Struct(_, fields) => {
|
||||
for field in fields {
|
||||
if field.attrs.flatten() {
|
||||
has_flatten = true;
|
||||
}
|
||||
field.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if has_flatten {
|
||||
attrs.mark_has_flatten();
|
||||
}
|
||||
|
||||
let mut item = Container {
|
||||
ident: item.ident.clone(),
|
||||
attrs,
|
||||
|
||||
@@ -185,8 +185,8 @@ impl Name {
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct RenameAllRules {
|
||||
serialize: RenameRule,
|
||||
deserialize: RenameRule,
|
||||
pub serialize: RenameRule,
|
||||
pub deserialize: RenameRule,
|
||||
}
|
||||
|
||||
impl RenameAllRules {
|
||||
@@ -216,7 +216,6 @@ pub struct Container {
|
||||
type_into: Option<syn::Type>,
|
||||
remote: Option<syn::Path>,
|
||||
identifier: Identifier,
|
||||
has_flatten: bool,
|
||||
serde_path: Option<syn::Path>,
|
||||
is_packed: bool,
|
||||
/// Error message generated when type can't be deserialized
|
||||
@@ -587,7 +586,6 @@ impl Container {
|
||||
type_into: type_into.get(),
|
||||
remote: remote.get(),
|
||||
identifier: decide_identifier(cx, item, field_identifier, variant_identifier),
|
||||
has_flatten: false,
|
||||
serde_path: serde_path.get(),
|
||||
is_packed,
|
||||
expecting: expecting.get(),
|
||||
@@ -655,14 +653,6 @@ impl Container {
|
||||
self.identifier
|
||||
}
|
||||
|
||||
pub fn has_flatten(&self) -> bool {
|
||||
self.has_flatten
|
||||
}
|
||||
|
||||
pub fn mark_has_flatten(&mut self) {
|
||||
self.has_flatten = true;
|
||||
}
|
||||
|
||||
pub fn custom_serde_path(&self) -> Option<&syn::Path> {
|
||||
self.serde_path.as_ref()
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ impl ReplaceReceiver<'_> {
|
||||
self.visit_type_mut_impl(ty);
|
||||
return;
|
||||
};
|
||||
*ty = self.self_ty(span).into();
|
||||
*ty = Type::Path(self.self_ty(span));
|
||||
}
|
||||
|
||||
// `Self::Assoc` -> `<Receiver>::Assoc`
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
//!
|
||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.197")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.210")]
|
||||
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
|
||||
// Ignored clippy lints
|
||||
#![allow(
|
||||
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
|
||||
|
||||
+13
-22
@@ -289,9 +289,18 @@ fn serialize_tuple_struct(
|
||||
}
|
||||
|
||||
fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Container) -> Fragment {
|
||||
assert!(fields.len() as u64 <= u64::from(u32::max_value()));
|
||||
assert!(
|
||||
fields.len() as u64 <= u64::from(u32::MAX),
|
||||
"too many fields in {}: {}, maximum supported count is {}",
|
||||
cattrs.name().serialize_name(),
|
||||
fields.len(),
|
||||
u32::MAX,
|
||||
);
|
||||
|
||||
if cattrs.has_flatten() {
|
||||
let has_non_skipped_flatten = fields
|
||||
.iter()
|
||||
.any(|field| field.attrs.flatten() && !field.attrs.skip_serializing());
|
||||
if has_non_skipped_flatten {
|
||||
serialize_struct_as_map(params, fields, cattrs)
|
||||
} else {
|
||||
serialize_struct_as_struct(params, fields, cattrs)
|
||||
@@ -370,26 +379,8 @@ fn serialize_struct_as_map(
|
||||
|
||||
let let_mut = mut_if(serialized_fields.peek().is_some() || tag_field_exists);
|
||||
|
||||
let len = if cattrs.has_flatten() {
|
||||
quote!(_serde::__private::None)
|
||||
} else {
|
||||
let len = serialized_fields
|
||||
.map(|field| match field.attrs.skip_serializing_if() {
|
||||
None => quote!(1),
|
||||
Some(path) => {
|
||||
let field_expr = get_member(params, field, &field.member);
|
||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||
}
|
||||
})
|
||||
.fold(
|
||||
quote!(#tag_field_exists as usize),
|
||||
|sum, expr| quote!(#sum + #expr),
|
||||
);
|
||||
quote!(_serde::__private::Some(#len))
|
||||
};
|
||||
|
||||
quote_block! {
|
||||
let #let_mut __serde_state = _serde::Serializer::serialize_map(__serializer, #len)?;
|
||||
let #let_mut __serde_state = _serde::Serializer::serialize_map(__serializer, _serde::__private::None)?;
|
||||
#tag_field
|
||||
#(#serialize_fields)*
|
||||
_serde::ser::SerializeMap::end(__serde_state)
|
||||
@@ -397,7 +388,7 @@ fn serialize_struct_as_map(
|
||||
}
|
||||
|
||||
fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Container) -> Fragment {
|
||||
assert!(variants.len() as u64 <= u64::from(u32::max_value()));
|
||||
assert!(variants.len() as u64 <= u64::from(u32::MAX));
|
||||
|
||||
let self_var = ¶ms.self_var;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "serde_derive_internals"
|
||||
version = "0.29.0"
|
||||
version = "0.29.1"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
description = "AST representation used by Serde derive macros. Unstable."
|
||||
documentation = "https://docs.rs/serde_derive_internals"
|
||||
edition = "2015"
|
||||
exclude = ["build.rs"]
|
||||
homepage = "https://serde.rs"
|
||||
keywords = ["serde", "serialization"]
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
// Warning: build.rs is not published to crates.io.
|
||||
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=src/mod.rs");
|
||||
|
||||
println!("cargo:rustc-cfg=check_cfg");
|
||||
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
|
||||
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
|
||||
println!("cargo:rustc-check-cfg=cfg(serde_build_from_git)");
|
||||
println!("cargo:rustc-check-cfg=cfg(feature, values(\"deserialize_in_place\"))");
|
||||
|
||||
// Sometimes on Windows the git checkout does not correctly wire up the
|
||||
// symlink from serde_derive_internals/src to serde_derive/src/internals.
|
||||
// When this happens we'll just build based on relative paths within the git
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.29.0")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.29.1")]
|
||||
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
|
||||
// Ignored clippy lints
|
||||
#![allow(
|
||||
clippy::cognitive_complexity,
|
||||
|
||||
@@ -18,4 +18,4 @@ rustversion = "1.0"
|
||||
serde = { path = "../serde", features = ["rc"] }
|
||||
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
||||
serde_test = "1.0.176"
|
||||
trybuild = { version = "1.0.66", features = ["diff"] }
|
||||
trybuild = { version = "1.0.97", features = ["diff"] }
|
||||
|
||||
@@ -23,21 +23,21 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Unit;
|
||||
pub struct Unit;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Newtype(u8);
|
||||
pub struct Newtype(u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Tuple(u8, u8);
|
||||
pub struct Tuple(u8, u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Struct {
|
||||
pub struct Struct {
|
||||
f: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Enum {
|
||||
pub enum Enum {
|
||||
Unit,
|
||||
Newtype(u8),
|
||||
Tuple(u8, u8),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||
#[rustversion::attr(not(nightly), ignore)]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
#[cfg_attr(target_os = "emscripten", ignore = "disabled on Emscripten")]
|
||||
#[rustversion::attr(not(nightly), ignore = "requires nightly")]
|
||||
#[cfg_attr(miri, ignore = "incompatible with miri")]
|
||||
#[allow(unused_attributes)]
|
||||
#[test]
|
||||
fn ui() {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#![allow(dead_code)] // we do not read enum fields
|
||||
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Nested;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub enum ExternallyTagged1 {
|
||||
Tuple(f64, String),
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub enum ExternallyTagged2 {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
Tuple(f64, String),
|
||||
}
|
||||
|
||||
// Internally tagged enums cannot contain tuple variants so not tested here
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "tag", content = "content")]
|
||||
pub enum AdjacentlyTagged1 {
|
||||
Tuple(f64, String),
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "tag", content = "content")]
|
||||
pub enum AdjacentlyTagged2 {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
Tuple(f64, String),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Untagged1 {
|
||||
Tuple(f64, String),
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Untagged2 {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
nested: Nested,
|
||||
},
|
||||
Tuple(f64, String),
|
||||
}
|
||||
@@ -7,7 +7,9 @@ pub struct Nested;
|
||||
pub enum ExternallyTagged {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
#[allow(dead_code)]
|
||||
nested: Nested,
|
||||
#[allow(dead_code)]
|
||||
string: &'static str,
|
||||
},
|
||||
}
|
||||
@@ -17,7 +19,9 @@ pub enum ExternallyTagged {
|
||||
pub enum InternallyTagged {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
#[allow(dead_code)]
|
||||
nested: Nested,
|
||||
#[allow(dead_code)]
|
||||
string: &'static str,
|
||||
},
|
||||
}
|
||||
@@ -27,7 +31,9 @@ pub enum InternallyTagged {
|
||||
pub enum AdjacentlyTagged {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
#[allow(dead_code)]
|
||||
nested: Nested,
|
||||
#[allow(dead_code)]
|
||||
string: &'static str,
|
||||
},
|
||||
}
|
||||
@@ -37,7 +43,9 @@ pub enum AdjacentlyTagged {
|
||||
pub enum UntaggedWorkaround {
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
#[allow(dead_code)]
|
||||
nested: Nested,
|
||||
#[allow(dead_code)]
|
||||
string: &'static str,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serde_test::{assert_tokens, Token};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
enum Enum {
|
||||
Simple {
|
||||
a: i32,
|
||||
},
|
||||
Flatten {
|
||||
#[serde(flatten)]
|
||||
flatten: (),
|
||||
a: i32,
|
||||
},
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_variant() {
|
||||
assert_tokens(
|
||||
&Enum::Simple { a: 42 },
|
||||
&[
|
||||
Token::StructVariant { name: "Enum", variant: "Simple", len: 1 },
|
||||
Token::Str("a"),
|
||||
Token::I32(42),
|
||||
Token::StructVariantEnd,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_variant() {
|
||||
assert_tokens(
|
||||
&Enum::Flatten { flatten: (), a: 42 },
|
||||
&[
|
||||
Token::NewtypeVariant { name: "Enum", variant: "Flatten" },
|
||||
Token::Map { len: None },
|
||||
Token::Str("a"),
|
||||
Token::I32(42),
|
||||
Token::MapEnd,
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#![allow(dead_code)] // we do not read enum fields
|
||||
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub enum A {
|
||||
B {
|
||||
c: String,
|
||||
},
|
||||
D {
|
||||
#[serde(flatten)]
|
||||
e: E,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct E {}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -162,7 +162,7 @@ fn test_cow() {
|
||||
#[test]
|
||||
fn test_lifetimes() {
|
||||
#[derive(Deserialize)]
|
||||
struct Cows<'a, 'b> {
|
||||
pub struct Cows<'a, 'b> {
|
||||
_copied: Cow<'a, str>,
|
||||
|
||||
#[serde(borrow)]
|
||||
@@ -178,7 +178,7 @@ fn test_lifetimes() {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Wrap<'a, 'b> {
|
||||
pub struct Wrap<'a, 'b> {
|
||||
#[serde(borrow = "'b")]
|
||||
_cows: Cows<'a, 'b>,
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::iter;
|
||||
use std::net;
|
||||
use std::num::{
|
||||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
||||
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Wrapping,
|
||||
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Saturating, Wrapping,
|
||||
};
|
||||
use std::ops::Bound;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -93,7 +93,7 @@ struct StructSkipDefault {
|
||||
|
||||
#[derive(PartialEq, Debug, Deserialize)]
|
||||
#[serde(default)]
|
||||
struct StructSkipDefaultGeneric<T> {
|
||||
pub struct StructSkipDefaultGeneric<T> {
|
||||
#[serde(skip_deserializing)]
|
||||
t: T,
|
||||
}
|
||||
@@ -2065,6 +2065,43 @@ fn test_wrapping() {
|
||||
test(Wrapping(1usize), &[Token::U64(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saturating() {
|
||||
test(Saturating(1usize), &[Token::U32(1)]);
|
||||
test(Saturating(1usize), &[Token::U64(1)]);
|
||||
test(Saturating(0u8), &[Token::I8(0)]);
|
||||
test(Saturating(0u16), &[Token::I16(0)]);
|
||||
|
||||
// saturate input values at the minimum or maximum value
|
||||
test(Saturating(u8::MAX), &[Token::U16(u16::MAX)]);
|
||||
test(Saturating(u8::MAX), &[Token::U16(u8::MAX as u16 + 1)]);
|
||||
test(Saturating(u16::MAX), &[Token::U32(u32::MAX)]);
|
||||
test(Saturating(u32::MAX), &[Token::U64(u64::MAX)]);
|
||||
test(Saturating(u8::MIN), &[Token::I8(i8::MIN)]);
|
||||
test(Saturating(u16::MIN), &[Token::I16(i16::MIN)]);
|
||||
test(Saturating(u32::MIN), &[Token::I32(i32::MIN)]);
|
||||
test(Saturating(i8::MIN), &[Token::I16(i16::MIN)]);
|
||||
test(Saturating(i16::MIN), &[Token::I32(i32::MIN)]);
|
||||
test(Saturating(i32::MIN), &[Token::I64(i64::MIN)]);
|
||||
|
||||
test(Saturating(u8::MIN), &[Token::I8(-1)]);
|
||||
test(Saturating(u16::MIN), &[Token::I16(-1)]);
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
{
|
||||
test(Saturating(usize::MIN), &[Token::U64(u64::MIN)]);
|
||||
test(Saturating(usize::MAX), &[Token::U64(u64::MAX)]);
|
||||
test(Saturating(isize::MIN), &[Token::I64(i64::MIN)]);
|
||||
test(Saturating(isize::MAX), &[Token::I64(i64::MAX)]);
|
||||
test(Saturating(0usize), &[Token::I64(i64::MIN)]);
|
||||
|
||||
test(
|
||||
Saturating(9_223_372_036_854_775_807usize),
|
||||
&[Token::I64(i64::MAX)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rc_dst() {
|
||||
test(Rc::<str>::from("s"), &[Token::Str("s")]);
|
||||
|
||||
@@ -1438,6 +1438,14 @@ fn test_integer_from_float() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nan_no_decimal_point() {
|
||||
assert_de_tokens_error::<isize>(
|
||||
&[Token::F32(f32::NAN)],
|
||||
"invalid type: floating point `NaN`, expected isize",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_struct_from_seq() {
|
||||
assert_de_tokens_error::<UnitStruct>(
|
||||
@@ -1459,7 +1467,7 @@ fn test_duration_overflow_seq() {
|
||||
assert_de_tokens_error::<Duration>(
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::U64(u64::max_value()),
|
||||
Token::U64(u64::MAX),
|
||||
Token::U32(1_000_000_000),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
@@ -1476,7 +1484,7 @@ fn test_duration_overflow_struct() {
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("secs"),
|
||||
Token::U64(u64::max_value()),
|
||||
Token::U64(u64::MAX),
|
||||
Token::Str("nanos"),
|
||||
Token::U32(1_000_000_000),
|
||||
Token::StructEnd,
|
||||
@@ -1490,7 +1498,7 @@ fn test_systemtime_overflow_seq() {
|
||||
assert_de_tokens_error::<SystemTime>(
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::U64(u64::max_value()),
|
||||
Token::U64(u64::MAX),
|
||||
Token::U32(1_000_000_000),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
@@ -1507,7 +1515,7 @@ fn test_systemtime_overflow_struct() {
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("secs_since_epoch"),
|
||||
Token::U64(u64::max_value()),
|
||||
Token::U64(u64::MAX),
|
||||
Token::Str("nanos_since_epoch"),
|
||||
Token::U32(1_000_000_000),
|
||||
Token::StructEnd,
|
||||
@@ -1516,13 +1524,12 @@ fn test_systemtime_overflow_struct() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(systemtime_checked_add)]
|
||||
#[test]
|
||||
fn test_systemtime_overflow() {
|
||||
assert_de_tokens_error::<SystemTime>(
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::U64(u64::max_value()),
|
||||
Token::U64(u64::MAX),
|
||||
Token::U32(0),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
|
||||
@@ -0,0 +1,799 @@
|
||||
#![deny(trivial_numeric_casts)]
|
||||
#![allow(
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
clippy::enum_variant_names,
|
||||
clippy::redundant_field_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
enum AdjacentlyTagged<T> {
|
||||
Unit,
|
||||
Newtype(T),
|
||||
Tuple(u8, u8),
|
||||
Struct { f: u8 },
|
||||
}
|
||||
|
||||
mod unit {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map_str_tag_only() {
|
||||
// Map: tag only
|
||||
assert_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: tag only and incorrect hint for number of elements
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_int_tag_only() {
|
||||
// Map: tag (as number) only
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::U16(0),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_bytes_tag_only() {
|
||||
// Map: tag only
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Bytes(b"t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: tag only
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::BorrowedBytes(b"t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_str_tag_content() {
|
||||
// Map: tag + content
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
// Map: content + tag
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: tag + content + excess fields (f, g, h)
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("f"),
|
||||
Token::Unit,
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::Str("g"),
|
||||
Token::Unit,
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::Str("h"),
|
||||
Token::Unit,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_int_tag_content() {
|
||||
// Map: tag (as number) + content (as number)
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::U8(0),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::U8(1),
|
||||
Token::Unit,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: content (as number) + tag (as number)
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::U64(1),
|
||||
Token::Unit,
|
||||
Token::U64(0),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_bytes_tag_content() {
|
||||
// Map: tag + content
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::BorrowedBytes(b"t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::BorrowedBytes(b"c"),
|
||||
Token::Unit,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: content + tag
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Bytes(b"c"),
|
||||
Token::Unit,
|
||||
Token::Bytes(b"t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seq_tag_content() {
|
||||
// Seq: tag and content
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::Unit,
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Seq: tag (as string) and content
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Seq { len: None },
|
||||
Token::Str("Unit"), // tag
|
||||
Token::Unit, // content
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Seq: tag (as borrowed string) and content
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit::<u8>,
|
||||
&[
|
||||
Token::Seq { len: None },
|
||||
Token::BorrowedStr("Unit"), // tag
|
||||
Token::Unit, // content
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod newtype {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map_tag_only() {
|
||||
// optional newtype with no content field
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Newtype::<Option<u8>>(None),
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_tag_content() {
|
||||
let value = AdjacentlyTagged::Newtype::<u8>(1);
|
||||
|
||||
// Map: tag + content
|
||||
assert_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::U8(1),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: content + tag
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::U8(1),
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seq() {
|
||||
let value = AdjacentlyTagged::Newtype::<u8>(1);
|
||||
|
||||
// Seq: tag and content
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::U8(1),
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Seq: tag (as string) and content
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: None },
|
||||
Token::Str("Newtype"), // tag
|
||||
Token::U8(1), // content
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Seq: tag (as borrowed string) and content
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: None },
|
||||
Token::BorrowedStr("Newtype"), // tag
|
||||
Token::U8(1), // content
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_with_newtype() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct NewtypeStruct(u32);
|
||||
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Newtype(NewtypeStruct(5)),
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::NewtypeStruct {
|
||||
name: "NewtypeStruct",
|
||||
},
|
||||
Token::U32(5),
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
mod tuple {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map() {
|
||||
let value = AdjacentlyTagged::Tuple::<u8>(1, 1);
|
||||
|
||||
// Map: tag + content
|
||||
assert_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Tuple",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Tuple { len: 2 },
|
||||
Token::U8(1),
|
||||
Token::U8(1),
|
||||
Token::TupleEnd,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: content + tag
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Tuple { len: 2 },
|
||||
Token::U8(1),
|
||||
Token::U8(1),
|
||||
Token::TupleEnd,
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Tuple",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seq() {
|
||||
let value = AdjacentlyTagged::Tuple::<u8>(1, 1);
|
||||
|
||||
// Seq: tag + content
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Tuple",
|
||||
},
|
||||
Token::Tuple { len: 2 },
|
||||
Token::U8(1),
|
||||
Token::U8(1),
|
||||
Token::TupleEnd,
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod struct_ {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map() {
|
||||
let value = AdjacentlyTagged::Struct::<u8> { f: 1 };
|
||||
|
||||
// Map: tag + content
|
||||
assert_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Struct",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Struct {
|
||||
name: "Struct",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("f"),
|
||||
Token::U8(1),
|
||||
Token::StructEnd,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Map: content + tag
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Struct {
|
||||
name: "Struct",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("f"),
|
||||
Token::U8(1),
|
||||
Token::StructEnd,
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Struct",
|
||||
},
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seq() {
|
||||
let value = AdjacentlyTagged::Struct::<u8> { f: 1 };
|
||||
|
||||
// Seq: tag + content
|
||||
assert_de_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::Seq { len: Some(2) },
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Struct",
|
||||
},
|
||||
Token::Struct {
|
||||
name: "Struct",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("f"),
|
||||
Token::U8(1),
|
||||
Token::StructEnd,
|
||||
Token::SeqEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn struct_with_flatten() {
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
enum Data {
|
||||
A {
|
||||
a: i32,
|
||||
#[serde(flatten)]
|
||||
flat: Flat,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
struct Flat {
|
||||
b: i32,
|
||||
}
|
||||
|
||||
let data = Data::A {
|
||||
a: 0,
|
||||
flat: Flat { b: 0 },
|
||||
};
|
||||
|
||||
assert_tokens(
|
||||
&data,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Data",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "Data",
|
||||
variant: "A",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Map { len: None },
|
||||
Token::Str("a"),
|
||||
Token::I32(0),
|
||||
Token::Str("b"),
|
||||
Token::I32(0),
|
||||
Token::MapEnd,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expecting_message() {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "tag", content = "content")]
|
||||
#[serde(expecting = "something strange...")]
|
||||
enum Enum {
|
||||
AdjacentlyTagged,
|
||||
}
|
||||
|
||||
assert_de_tokens_error::<Enum>(
|
||||
&[Token::Str("AdjacentlyTagged")],
|
||||
r#"invalid type: string "AdjacentlyTagged", expected something strange..."#,
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<Enum>(
|
||||
&[Token::Map { len: None }, Token::Unit],
|
||||
r#"invalid type: unit value, expected "tag", "content", or other ignored fields"#,
|
||||
);
|
||||
|
||||
// Check that #[serde(expecting = "...")] doesn't affect variant identifier error message
|
||||
assert_de_tokens_error::<Enum>(
|
||||
&[Token::Map { len: None }, Token::Str("tag"), Token::Unit],
|
||||
"invalid type: unit value, expected variant of enum Enum",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partially_untagged() {
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
enum Data {
|
||||
A(u32),
|
||||
B,
|
||||
#[serde(untagged)]
|
||||
Var(u32),
|
||||
}
|
||||
|
||||
let data = Data::A(7);
|
||||
|
||||
assert_de_tokens(
|
||||
&data,
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::Str("t"),
|
||||
Token::Str("A"),
|
||||
Token::Str("c"),
|
||||
Token::U32(7),
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
|
||||
let data = Data::Var(42);
|
||||
|
||||
assert_de_tokens(&data, &[Token::U32(42)]);
|
||||
|
||||
// TODO test error output
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deny_unknown_fields() {
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(tag = "t", content = "c", deny_unknown_fields)]
|
||||
enum AdjacentlyTagged {
|
||||
Unit,
|
||||
}
|
||||
|
||||
assert_de_tokens(
|
||||
&AdjacentlyTagged::Unit,
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("t"),
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::Str("h"),
|
||||
],
|
||||
r#"invalid value: string "h", expected "t" or "c""#,
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("h"),
|
||||
],
|
||||
r#"invalid value: string "h", expected "t" or "c""#,
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Str("c"),
|
||||
Token::Unit,
|
||||
Token::Str("h"),
|
||||
],
|
||||
r#"invalid value: string "h", expected "t" or "c""#,
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::U64(0), // tag field
|
||||
Token::UnitVariant {
|
||||
name: "AdjacentlyTagged",
|
||||
variant: "Unit",
|
||||
},
|
||||
Token::U64(3),
|
||||
],
|
||||
r#"invalid value: integer `3`, expected "t" or "c""#,
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "AdjacentlyTagged",
|
||||
len: 2,
|
||||
},
|
||||
Token::Bytes(b"c"),
|
||||
Token::Unit,
|
||||
Token::Bytes(b"h"),
|
||||
],
|
||||
r#"invalid value: byte array, expected "t" or "c""#,
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,583 @@
|
||||
#![deny(trivial_numeric_casts)]
|
||||
#![allow(
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
clippy::enum_variant_names,
|
||||
clippy::redundant_field_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
mod bytes;
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[test]
|
||||
fn complex() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Untagged {
|
||||
A { a: u8 },
|
||||
B { b: u8 },
|
||||
C,
|
||||
D(u8),
|
||||
E(String),
|
||||
F(u8, u8),
|
||||
}
|
||||
|
||||
assert_tokens(
|
||||
&Untagged::A { a: 1 },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("a"),
|
||||
Token::U8(1),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_tokens(
|
||||
&Untagged::B { b: 2 },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("b"),
|
||||
Token::U8(2),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
// Serializes to unit, deserializes from either depending on format's
|
||||
// preference.
|
||||
assert_tokens(&Untagged::C, &[Token::Unit]);
|
||||
assert_de_tokens(&Untagged::C, &[Token::None]);
|
||||
|
||||
assert_tokens(&Untagged::D(4), &[Token::U8(4)]);
|
||||
assert_tokens(&Untagged::E("e".to_owned()), &[Token::Str("e")]);
|
||||
|
||||
assert_tokens(
|
||||
&Untagged::F(1, 2),
|
||||
&[
|
||||
Token::Tuple { len: 2 },
|
||||
Token::U8(1),
|
||||
Token::U8(2),
|
||||
Token::TupleEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<Untagged>(
|
||||
&[Token::Tuple { len: 1 }, Token::U8(1), Token::TupleEnd],
|
||||
"data did not match any variant of untagged enum Untagged",
|
||||
);
|
||||
|
||||
assert_de_tokens_error::<Untagged>(
|
||||
&[
|
||||
Token::Tuple { len: 3 },
|
||||
Token::U8(1),
|
||||
Token::U8(2),
|
||||
Token::U8(3),
|
||||
Token::TupleEnd,
|
||||
],
|
||||
"data did not match any variant of untagged enum Untagged",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newtype_unit_and_empty_map() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Unit;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Message {
|
||||
Unit(Unit),
|
||||
Map(BTreeMap<String, String>),
|
||||
}
|
||||
|
||||
assert_tokens(
|
||||
&Message::Map(BTreeMap::new()),
|
||||
&[Token::Map { len: Some(0) }, Token::MapEnd],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::ContentRefDeserializer::deserialize_newtype_struct
|
||||
#[test]
|
||||
fn newtype_struct() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct NewtypeStruct(u32);
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum E {
|
||||
Newtype(NewtypeStruct),
|
||||
Null,
|
||||
}
|
||||
|
||||
let value = E::Newtype(NewtypeStruct(5));
|
||||
|
||||
// Content::Newtype case
|
||||
assert_tokens(
|
||||
&value,
|
||||
&[
|
||||
Token::NewtypeStruct {
|
||||
name: "NewtypeStruct",
|
||||
},
|
||||
Token::U32(5),
|
||||
],
|
||||
);
|
||||
|
||||
// _ case
|
||||
assert_de_tokens(&value, &[Token::U32(5)]);
|
||||
}
|
||||
|
||||
mod newtype_enum {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Outer {
|
||||
Inner(Inner),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
enum Inner {
|
||||
Unit,
|
||||
Newtype(u8),
|
||||
Tuple0(),
|
||||
Tuple2(u8, u8),
|
||||
Struct { f: u8 },
|
||||
EmptyStruct {},
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::unit_variant
|
||||
#[test]
|
||||
fn unit() {
|
||||
assert_tokens(
|
||||
&Outer::Inner(Inner::Unit),
|
||||
&[Token::UnitVariant {
|
||||
name: "Inner",
|
||||
variant: "Unit",
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::newtype_variant_seed
|
||||
#[test]
|
||||
fn newtype() {
|
||||
assert_tokens(
|
||||
&Outer::Inner(Inner::Newtype(1)),
|
||||
&[
|
||||
Token::NewtypeVariant {
|
||||
name: "Inner",
|
||||
variant: "Newtype",
|
||||
},
|
||||
Token::U8(1),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::tuple_variant
|
||||
#[test]
|
||||
fn tuple0() {
|
||||
assert_tokens(
|
||||
&Outer::Inner(Inner::Tuple0()),
|
||||
&[
|
||||
Token::TupleVariant {
|
||||
name: "Inner",
|
||||
variant: "Tuple0",
|
||||
len: 0,
|
||||
},
|
||||
Token::TupleVariantEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::tuple_variant
|
||||
#[test]
|
||||
fn tuple2() {
|
||||
assert_tokens(
|
||||
&Outer::Inner(Inner::Tuple2(1, 1)),
|
||||
&[
|
||||
Token::TupleVariant {
|
||||
name: "Inner",
|
||||
variant: "Tuple2",
|
||||
len: 2,
|
||||
},
|
||||
Token::U8(1),
|
||||
Token::U8(1),
|
||||
Token::TupleVariantEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
|
||||
// Content::Map case
|
||||
#[test]
|
||||
fn struct_from_map() {
|
||||
assert_tokens(
|
||||
&Outer::Inner(Inner::Struct { f: 1 }),
|
||||
&[
|
||||
Token::StructVariant {
|
||||
name: "Inner",
|
||||
variant: "Struct",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("f"),
|
||||
Token::U8(1),
|
||||
Token::StructVariantEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
|
||||
// Content::Seq case
|
||||
#[test]
|
||||
fn struct_from_seq() {
|
||||
assert_de_tokens(
|
||||
&Outer::Inner(Inner::Struct { f: 1 }),
|
||||
&[
|
||||
Token::Map { len: Some(1) },
|
||||
// tag
|
||||
Token::Str("Struct"),
|
||||
// content
|
||||
Token::Seq { len: Some(1) },
|
||||
Token::U8(1),
|
||||
Token::SeqEnd,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
|
||||
// Content::Map case
|
||||
// Special case - empty map
|
||||
#[test]
|
||||
fn empty_struct_from_map() {
|
||||
assert_de_tokens(
|
||||
&Outer::Inner(Inner::EmptyStruct {}),
|
||||
&[
|
||||
Token::Map { len: Some(1) },
|
||||
// tag
|
||||
Token::Str("EmptyStruct"),
|
||||
// content
|
||||
Token::Map { len: Some(0) },
|
||||
Token::MapEnd,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
|
||||
// Content::Seq case
|
||||
// Special case - empty seq
|
||||
#[test]
|
||||
fn empty_struct_from_seq() {
|
||||
assert_de_tokens(
|
||||
&Outer::Inner(Inner::EmptyStruct {}),
|
||||
&[
|
||||
Token::Map { len: Some(1) },
|
||||
// tag
|
||||
Token::Str("EmptyStruct"),
|
||||
// content
|
||||
Token::Seq { len: Some(0) },
|
||||
Token::SeqEnd,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Reaches crate::private::de::content::ContentRefDeserializer::deserialize_option
|
||||
mod with_optional_field {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Enum {
|
||||
Struct { optional: Option<u32> },
|
||||
Null,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
assert_tokens(
|
||||
&Enum::Struct { optional: Some(42) },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Enum",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("optional"),
|
||||
Token::Some,
|
||||
Token::U32(42),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some_without_marker() {
|
||||
assert_de_tokens(
|
||||
&Enum::Struct { optional: Some(42) },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Enum",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("optional"),
|
||||
Token::U32(42),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
assert_tokens(
|
||||
&Enum::Struct { optional: None },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Enum",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("optional"),
|
||||
Token::None,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unit() {
|
||||
assert_de_tokens(
|
||||
&Enum::Struct { optional: None },
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::Str("optional"),
|
||||
Token::Unit,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_and_bytes() {
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Untagged {
|
||||
String {
|
||||
string: String,
|
||||
},
|
||||
Bytes {
|
||||
#[serde(with = "bytes")]
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
}
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::String {
|
||||
string: "\0".to_owned(),
|
||||
},
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("string"),
|
||||
Token::Str("\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::String {
|
||||
string: "\0".to_owned(),
|
||||
},
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("string"),
|
||||
Token::String("\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::String {
|
||||
string: "\0".to_owned(),
|
||||
},
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("string"),
|
||||
Token::Bytes(b"\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::String {
|
||||
string: "\0".to_owned(),
|
||||
},
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("string"),
|
||||
Token::ByteBuf(b"\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::Bytes { bytes: vec![0] },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("bytes"),
|
||||
Token::Str("\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::Bytes { bytes: vec![0] },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("bytes"),
|
||||
Token::String("\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::Bytes { bytes: vec![0] },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("bytes"),
|
||||
Token::Bytes(b"\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::Bytes { bytes: vec![0] },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("bytes"),
|
||||
Token::ByteBuf(b"\0"),
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
|
||||
assert_de_tokens(
|
||||
&Untagged::Bytes { bytes: vec![0] },
|
||||
&[
|
||||
Token::Struct {
|
||||
name: "Untagged",
|
||||
len: 1,
|
||||
},
|
||||
Token::Str("bytes"),
|
||||
Token::Seq { len: Some(1) },
|
||||
Token::U8(0),
|
||||
Token::SeqEnd,
|
||||
Token::StructEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contains_flatten() {
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
#[serde(untagged)]
|
||||
enum Data {
|
||||
A {
|
||||
a: i32,
|
||||
#[serde(flatten)]
|
||||
flat: Flat,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
struct Flat {
|
||||
b: i32,
|
||||
}
|
||||
|
||||
let data = Data::A {
|
||||
a: 0,
|
||||
flat: Flat { b: 0 },
|
||||
};
|
||||
|
||||
assert_tokens(
|
||||
&data,
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::Str("a"),
|
||||
Token::I32(0),
|
||||
Token::Str("b"),
|
||||
Token::I32(0),
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contains_flatten_with_integer_key() {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Untagged {
|
||||
Variant {
|
||||
#[serde(flatten)]
|
||||
map: BTreeMap<u64, String>,
|
||||
},
|
||||
}
|
||||
|
||||
assert_tokens(
|
||||
&Untagged::Variant {
|
||||
map: {
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert(100, "BTreeMap".to_owned());
|
||||
map
|
||||
},
|
||||
},
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::U64(100),
|
||||
Token::Str("BTreeMap"),
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expecting_message() {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
#[serde(expecting = "something strange...")]
|
||||
enum Enum {
|
||||
Untagged,
|
||||
}
|
||||
|
||||
assert_de_tokens_error::<Enum>(&[Token::Str("Untagged")], "something strange...");
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#![deny(warnings)]
|
||||
#![allow(
|
||||
confusable_idents,
|
||||
unknown_lints,
|
||||
mixed_script_confusables,
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
@@ -19,6 +20,7 @@
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
clippy::type_repetition_in_bounds
|
||||
)]
|
||||
#![deny(clippy::collection_is_never_read)]
|
||||
|
||||
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
@@ -287,60 +289,60 @@ fn test_gen() {
|
||||
assert::<EmptyEnumVariant>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct NonAsciiIdents {
|
||||
pub struct NonAsciiIdents {
|
||||
σ: f64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct EmptyBraced {}
|
||||
pub struct EmptyBraced {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct EmptyBracedDenyUnknown {}
|
||||
pub struct EmptyBracedDenyUnknown {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct BracedSkipAll {
|
||||
pub struct BracedSkipAll {
|
||||
#[serde(skip_deserializing)]
|
||||
f: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct BracedSkipAllDenyUnknown {
|
||||
pub struct BracedSkipAllDenyUnknown {
|
||||
#[serde(skip_deserializing)]
|
||||
f: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct EmptyTuple();
|
||||
pub struct EmptyTuple();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct EmptyTupleDenyUnknown();
|
||||
pub struct EmptyTupleDenyUnknown();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TupleSkipAll(#[serde(skip_deserializing)] u8);
|
||||
pub struct TupleSkipAll(#[serde(skip_deserializing)] u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
|
||||
pub struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum EmptyEnum {}
|
||||
pub enum EmptyEnum {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
enum EmptyEnumDenyUnknown {}
|
||||
pub enum EmptyEnumDenyUnknown {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum EnumSkipAll {
|
||||
pub enum EnumSkipAll {
|
||||
#[serde(skip_deserializing)]
|
||||
#[allow(dead_code)]
|
||||
Variant,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum EmptyVariants {
|
||||
pub enum EmptyVariants {
|
||||
Braced {},
|
||||
Tuple(),
|
||||
BracedSkip {
|
||||
@@ -352,7 +354,7 @@ fn test_gen() {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
enum EmptyVariantsDenyUnknown {
|
||||
pub enum EmptyVariantsDenyUnknown {
|
||||
Braced {},
|
||||
Tuple(),
|
||||
BracedSkip {
|
||||
@@ -364,21 +366,21 @@ fn test_gen() {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct UnitDenyUnknown;
|
||||
pub struct UnitDenyUnknown;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct EmptyArray {
|
||||
pub struct EmptyArray {
|
||||
empty: [X; 0],
|
||||
}
|
||||
|
||||
enum Or<A, B> {
|
||||
pub enum Or<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(untagged, remote = "Or")]
|
||||
enum OrDef<A, B> {
|
||||
pub enum OrDef<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
@@ -390,7 +392,7 @@ fn test_gen() {
|
||||
struct StrDef<'a>(&'a str);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Remote<'a> {
|
||||
pub struct Remote<'a> {
|
||||
#[serde(with = "OrDef")]
|
||||
or: Or<u8, bool>,
|
||||
#[serde(borrow, with = "StrDef")]
|
||||
@@ -398,7 +400,7 @@ fn test_gen() {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum BorrowVariant<'a> {
|
||||
pub enum BorrowVariant<'a> {
|
||||
#[serde(borrow, with = "StrDef")]
|
||||
S(Str<'a>),
|
||||
}
|
||||
@@ -415,14 +417,14 @@ fn test_gen() {
|
||||
|
||||
// This would not work if SDef::serialize / deserialize are private.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct RemoteVisibility {
|
||||
pub struct RemoteVisibility {
|
||||
#[serde(with = "vis::SDef")]
|
||||
s: vis::S,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "Self")]
|
||||
struct RemoteSelf;
|
||||
pub struct RemoteSelf;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum ExternallyTaggedVariantWith {
|
||||
@@ -546,26 +548,45 @@ fn test_gen() {
|
||||
assert::<FlattenWith>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct FlattenDenyUnknown<T> {
|
||||
pub struct Flatten<T> {
|
||||
#[serde(flatten)]
|
||||
t: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct StaticStrStruct<'a> {
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct FlattenDenyUnknown<T> {
|
||||
#[serde(flatten)]
|
||||
t: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SkipDeserializing<T> {
|
||||
#[serde(skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SkipDeserializingDenyUnknown<T> {
|
||||
#[serde(skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StaticStrStruct<'a> {
|
||||
a: &'a str,
|
||||
b: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct StaticStrTupleStruct<'a>(&'a str, &'static str);
|
||||
pub struct StaticStrTupleStruct<'a>(&'a str, &'static str);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct StaticStrNewtypeStruct(&'static str);
|
||||
pub struct StaticStrNewtypeStruct(&'static str);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum StaticStrEnum<'a> {
|
||||
pub enum StaticStrEnum<'a> {
|
||||
Struct { a: &'a str, b: &'static str },
|
||||
Tuple(&'a str, &'static str),
|
||||
Newtype(&'static str),
|
||||
@@ -639,6 +660,7 @@ fn test_gen() {
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
struct Restricted {
|
||||
pub(super) a: usize,
|
||||
pub(in super::inner) b: usize,
|
||||
@@ -648,7 +670,7 @@ fn test_gen() {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
enum AdjacentlyTaggedVoid {}
|
||||
pub enum AdjacentlyTaggedVoid {}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum SkippedVariant<T> {
|
||||
@@ -661,14 +683,13 @@ fn test_gen() {
|
||||
assert::<SkippedVariant<X>>();
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ImplicitlyBorrowedOption<'a> {
|
||||
#[allow(dead_code)]
|
||||
pub struct ImplicitlyBorrowedOption<'a> {
|
||||
option: std::option::Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum UntaggedNewtypeVariantWith {
|
||||
pub enum UntaggedNewtypeVariantWith {
|
||||
Newtype(
|
||||
#[serde(serialize_with = "ser_x")]
|
||||
#[serde(deserialize_with = "de_x")]
|
||||
@@ -678,7 +699,7 @@ fn test_gen() {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
struct TransparentWith {
|
||||
pub struct TransparentWith {
|
||||
#[serde(serialize_with = "ser_x")]
|
||||
#[serde(deserialize_with = "de_x")]
|
||||
x: X,
|
||||
@@ -687,40 +708,59 @@ fn test_gen() {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum UntaggedWithBorrow<'a> {
|
||||
Single(#[serde(borrow)] RelObject<'a>),
|
||||
Many(#[serde(borrow)] Vec<RelObject<'a>>),
|
||||
Single(
|
||||
#[serde(borrow)]
|
||||
#[allow(dead_code)]
|
||||
RelObject<'a>,
|
||||
),
|
||||
Many(
|
||||
#[serde(borrow)]
|
||||
#[allow(dead_code)]
|
||||
Vec<RelObject<'a>>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RelObject<'a> {
|
||||
#[allow(dead_code)]
|
||||
pub struct RelObject<'a> {
|
||||
ty: &'a str,
|
||||
#[allow(dead_code)]
|
||||
id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct FlattenSkipSerializing<T> {
|
||||
pub struct FlattenSkipSerializing<T> {
|
||||
#[serde(flatten, skip_serializing)]
|
||||
#[allow(dead_code)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct FlattenSkipSerializingIf<T> {
|
||||
pub struct FlattenSkipSerializingIf<T> {
|
||||
#[serde(flatten, skip_serializing_if = "StdOption::is_none")]
|
||||
flat: StdOption<T>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct FlattenSkipDeserializing<T> {
|
||||
pub struct FlattenSkipDeserializing<T> {
|
||||
#[serde(flatten, skip_deserializing)]
|
||||
flat: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Inner<T> {
|
||||
Builder {
|
||||
s: T,
|
||||
#[serde(flatten)]
|
||||
o: T,
|
||||
},
|
||||
Default {
|
||||
s: T,
|
||||
},
|
||||
}
|
||||
|
||||
// https://github.com/serde-rs/serde/issues/1804
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Message {
|
||||
pub enum Message {
|
||||
#[serde(skip)]
|
||||
#[allow(dead_code)]
|
||||
String(String),
|
||||
@@ -730,6 +770,7 @@ fn test_gen() {
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[repr(packed)]
|
||||
#[allow(dead_code)]
|
||||
struct Packed {
|
||||
x: u8,
|
||||
y: u16,
|
||||
@@ -738,8 +779,7 @@ fn test_gen() {
|
||||
macro_rules! deriving {
|
||||
($field:ty) => {
|
||||
#[derive(Deserialize)]
|
||||
struct MacroRules<'a> {
|
||||
#[allow(dead_code)]
|
||||
pub struct MacroRules<'a> {
|
||||
field: $field,
|
||||
}
|
||||
};
|
||||
@@ -754,21 +794,20 @@ fn test_gen() {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct BorrowLifetimeInsideMacro<'a> {
|
||||
pub struct BorrowLifetimeInsideMacro<'a> {
|
||||
#[serde(borrow = "'a")]
|
||||
#[allow(dead_code)]
|
||||
f: mac!(Cow<'a, str>),
|
||||
pub f: mac!(Cow<'a, str>),
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Struct {
|
||||
pub struct Struct {
|
||||
#[serde(serialize_with = "vec_first_element")]
|
||||
vec: Vec<Self>,
|
||||
pub vec: Vec<Self>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(bound(deserialize = "[&'de str; N]: Copy"))]
|
||||
struct GenericUnitStruct<const N: usize>;
|
||||
pub struct GenericUnitStruct<const N: usize>;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -855,7 +894,7 @@ where
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(tag = "tag")]
|
||||
enum InternallyTagged {
|
||||
pub enum InternallyTagged {
|
||||
#[serde(deserialize_with = "deserialize_generic")]
|
||||
Unit,
|
||||
|
||||
|
||||
+5
-1382
File diff suppressed because it is too large
Load Diff
@@ -7,14 +7,17 @@ mod remote {
|
||||
|
||||
pub struct PrimitivePriv(u8);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct PrimitivePub(pub u8);
|
||||
|
||||
pub struct NewtypePriv(Unit);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct NewtypePub(pub Unit);
|
||||
|
||||
pub struct TuplePriv(u8, Unit);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct TuplePub(pub u8, pub Unit);
|
||||
|
||||
pub struct StructPriv {
|
||||
@@ -22,6 +25,7 @@ mod remote {
|
||||
b: Unit,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct StructPub {
|
||||
pub a: u8,
|
||||
pub b: Unit,
|
||||
@@ -86,12 +90,14 @@ mod remote {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum EnumGeneric<T> {
|
||||
Variant(T),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
struct Test {
|
||||
#[serde(with = "UnitDef")]
|
||||
unit: remote::Unit,
|
||||
@@ -132,6 +138,7 @@ struct Test {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::Unit")]
|
||||
#[allow(dead_code)]
|
||||
struct UnitDef;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -140,6 +147,7 @@ struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::PrimitivePub")]
|
||||
#[allow(dead_code)]
|
||||
struct PrimitivePubDef(u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -148,6 +156,7 @@ struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitD
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::NewtypePub")]
|
||||
#[allow(dead_code)]
|
||||
struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -159,6 +168,7 @@ struct TuplePrivDef(
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::TuplePub")]
|
||||
#[allow(dead_code)]
|
||||
struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -174,6 +184,7 @@ struct StructPrivDef {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::StructPub")]
|
||||
#[allow(dead_code)]
|
||||
struct StructPubDef {
|
||||
a: u8,
|
||||
|
||||
@@ -190,17 +201,20 @@ struct StructGenericWithGetterDef<T> {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::StructGeneric<u8>")]
|
||||
#[allow(dead_code)]
|
||||
struct StructConcrete {
|
||||
value: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "remote::EnumGeneric<u8>")]
|
||||
#[allow(dead_code)]
|
||||
enum EnumConcrete {
|
||||
Variant(u8),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
enum ErrorKind {
|
||||
NotFound,
|
||||
PermissionDenied,
|
||||
@@ -211,6 +225,7 @@ enum ErrorKind {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "ErrorKind")]
|
||||
#[non_exhaustive]
|
||||
#[allow(dead_code)]
|
||||
enum ErrorKindDef {
|
||||
NotFound,
|
||||
PermissionDenied,
|
||||
|
||||
@@ -41,7 +41,7 @@ fn test_self() {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Tuple(
|
||||
pub struct Tuple(
|
||||
Box<Self>,
|
||||
Box<<Self as Trait>::Assoc>,
|
||||
[(); Self::ASSOC],
|
||||
@@ -60,7 +60,7 @@ fn test_self() {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
enum Enum {
|
||||
pub enum Enum {
|
||||
Struct {
|
||||
_f1: Box<Self>,
|
||||
_f2: Box<<Self as Trait>::Assoc>,
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::cell::RefCell;
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
use std::ffi::CString;
|
||||
use std::net;
|
||||
use std::num::Wrapping;
|
||||
use std::num::{Saturating, Wrapping};
|
||||
use std::ops::Bound;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::{Rc, Weak as RcWeak};
|
||||
@@ -624,6 +624,11 @@ fn test_wrapping() {
|
||||
assert_ser_tokens(&Wrapping(1usize), &[Token::U64(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saturating() {
|
||||
assert_ser_tokens(&Saturating(1usize), &[Token::U64(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rc_dst() {
|
||||
assert_ser_tokens(&Rc::<str>::from("s"), &[Token::Str("s")]);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use serde::de::Deserialize;
|
||||
use serde::ser::Serialize;
|
||||
|
||||
fn to_string<T>(_: &T) -> String
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn from_str<'de, T>(_: &'de str) -> T
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
struct MyStruct;
|
||||
|
||||
fn main() {
|
||||
to_string(&MyStruct);
|
||||
let _: MyStruct = from_str("");
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
error[E0277]: the trait bound `MyStruct: Serialize` is not satisfied
|
||||
--> tests/ui/on_unimplemented.rs:21:15
|
||||
|
|
||||
21 | to_string(&MyStruct);
|
||||
| --------- ^^^^^^^^^ the trait `Serialize` is not implemented for `MyStruct`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: for local types consider adding `#[derive(serde::Serialize)]` to your `MyStruct` type
|
||||
= note: for types from other crates check whether the crate offers a `serde` feature flag
|
||||
= help: the following other types implement trait `Serialize`:
|
||||
&'a T
|
||||
&'a mut T
|
||||
()
|
||||
(T,)
|
||||
(T0, T1)
|
||||
(T0, T1, T2)
|
||||
(T0, T1, T2, T3)
|
||||
(T0, T1, T2, T3, T4)
|
||||
and $N others
|
||||
note: required by a bound in `to_string`
|
||||
--> tests/ui/on_unimplemented.rs:6:8
|
||||
|
|
||||
4 | fn to_string<T>(_: &T) -> String
|
||||
| --------- required by a bound in this function
|
||||
5 | where
|
||||
6 | T: Serialize,
|
||||
| ^^^^^^^^^ required by this bound in `to_string`
|
||||
|
||||
error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied
|
||||
--> tests/ui/on_unimplemented.rs:22:23
|
||||
|
|
||||
22 | let _: MyStruct = from_str("");
|
||||
| ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct`
|
||||
|
|
||||
= note: for local types consider adding `#[derive(serde::Deserialize)]` to your `MyStruct` type
|
||||
= note: for types from other crates check whether the crate offers a `serde` feature flag
|
||||
= help: the following other types implement trait `Deserialize<'de>`:
|
||||
&'a Path
|
||||
&'a [u8]
|
||||
&'a str
|
||||
()
|
||||
(T,)
|
||||
(T0, T1)
|
||||
(T0, T1, T2)
|
||||
(T0, T1, T2, T3)
|
||||
and $N others
|
||||
note: required by a bound in `from_str`
|
||||
--> tests/ui/on_unimplemented.rs:13:8
|
||||
|
|
||||
11 | fn from_str<'de, T>(_: &'de str) -> T
|
||||
| -------- required by a bound in this function
|
||||
12 | where
|
||||
13 | T: Deserialize<'de>,
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `from_str`
|
||||
Reference in New Issue
Block a user