Skip to content

Commit

Permalink
Merge pull request #2334 from dtolnay/mapimpl
Browse files Browse the repository at this point in the history
Reduce trait bounds in HashMap and BTreeMap serialize
  • Loading branch information
dtolnay authored Dec 5, 2022
2 parents 0353354 + 227d039 commit 3aec2a9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
where
K: Serialize,
V: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
Expand Down

0 comments on commit 3aec2a9

Please sign in to comment.