From 227d039b1ed8a51c57a9078f8738c26b12464662 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 4 Dec 2022 23:18:02 -0800 Subject: [PATCH] Reduce trait bounds in HashMap and BTreeMap serialize --- serde/src/ser/impls.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 1f1ad1711..bd4313c33 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -365,7 +365,26 @@ tuple_impls! { //////////////////////////////////////////////////////////////////////////////// -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))] +macro_rules! map_impl { + ($ty:ident < K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)* >) => { + impl Serialize for $ty + where + K: Serialize, + V: Serialize, + { + #[inline] + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.collect_map(self) + } + } + } +} + +#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))] macro_rules! map_impl { ($ty:ident < K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)* >) => { impl Serialize for $ty