From f28abe8fde465e3ca59bbffe2c323e465ddf6398 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 13 Apr 2017 16:09:53 -0700 Subject: [PATCH] Map impls more like the seq impls --- serde/src/ser/impls.rs | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 4d1a97e4..46d0601e 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -165,11 +165,11 @@ where } macro_rules! seq_impl { - ($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound1:ident $(+ $bound2:ident)*)* >) => { + ($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)* >) => { impl Serialize for $ty where T: Serialize $(+ $tbound1 $(+ $tbound2)*)*, - $($typaram: $bound1 $(+ $bound2)*)* + $($typaram: $bound,)* { #[inline] fn serialize(&self, serializer: S) -> Result @@ -276,35 +276,29 @@ tuple_impls! { //////////////////////////////////////////////////////////////////////////////// -macro_rules! serialize_map { - () => { - #[inline] - fn serialize(&self, serializer: S) -> Result - where S: Serializer, +macro_rules! map_impl { + ($ty:ident < K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)* >) => { + impl Serialize for $ty + where + K: Serialize $(+ $kbound1 $(+ $kbound2)*)*, + V: Serialize, + $($typaram: $bound,)* { - serializer.collect_map(self) + #[inline] + fn serialize(&self, serializer: S) -> Result + where S: Serializer, + { + serializer.collect_seq(self) + } } } } #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for BTreeMap -where - K: Serialize + Ord, - V: Serialize, -{ - serialize_map!(); -} +map_impl!(BTreeMap); #[cfg(feature = "std")] -impl Serialize for HashMap -where - K: Serialize + Eq + Hash, - V: Serialize, - H: BuildHasher, -{ - serialize_map!(); -} +map_impl!(HashMap); ////////////////////////////////////////////////////////////////////////////////