From a15636f808dc95064108bb4814145dc1f8ec33ee Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 13 Apr 2017 15:55:34 -0700 Subject: [PATCH] More like the Deserialize impls for sequences --- serde/src/ser/impls.rs | 78 ++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 1590ad60..9105d386 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -152,72 +152,52 @@ array_impls!(01 02 03 04 05 06 07 08 09 10 //////////////////////////////////////////////////////////////////////////////// -macro_rules! serialize_seq { - () => { - #[inline] - fn serialize(&self, serializer: S) -> Result - where S: Serializer, - { - serializer.collect_seq(self) - } - } -} - impl Serialize for [T] where T: Serialize, { - serialize_seq!(); + #[inline] + fn serialize(&self, serializer: S) -> Result + where S: Serializer, + { + serializer.collect_seq(self) + } +} + +macro_rules! seq_impl { + ($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound1:ident $(+ $bound2:ident)*)* >) => { + impl Serialize for $ty + where + T: Serialize $(+ $tbound1 $(+ $tbound2)*)*, + $($typaram: $bound1 $(+ $bound2)*)* + { + #[inline] + fn serialize(&self, serializer: S) -> Result + where S: Serializer, + { + serializer.collect_seq(self) + } + } + } } #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for BinaryHeap -where - T: Serialize + Ord, -{ - serialize_seq!(); -} +seq_impl!(BinaryHeap); #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for BTreeSet -where - T: Serialize + Ord, -{ - serialize_seq!(); -} +seq_impl!(BTreeSet); #[cfg(feature = "std")] -impl Serialize for HashSet -where - T: Serialize + Eq + Hash, - H: BuildHasher, -{ - serialize_seq!(); -} +seq_impl!(HashSet); #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for LinkedList -where - T: Serialize, -{ - serialize_seq!(); -} +seq_impl!(LinkedList); #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for Vec -where - T: Serialize, -{ - serialize_seq!(); -} +seq_impl!(Vec); #[cfg(any(feature = "std", feature = "collections"))] -impl Serialize for VecDeque -where - T: Serialize, -{ - serialize_seq!(); -} +seq_impl!(VecDeque); ////////////////////////////////////////////////////////////////////////////////