mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 20:11:02 +00:00
Map impls more like the seq impls
This commit is contained in:
+17
-23
@@ -165,11 +165,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! seq_impl {
|
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<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
|
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
|
||||||
where
|
where
|
||||||
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
|
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
|
||||||
$($typaram: $bound1 $(+ $bound2)*)*
|
$($typaram: $bound,)*
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -276,35 +276,29 @@ tuple_impls! {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! serialize_map {
|
macro_rules! map_impl {
|
||||||
() => {
|
($ty:ident < K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)* >) => {
|
||||||
#[inline]
|
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
where
|
||||||
where S: Serializer,
|
K: Serialize $(+ $kbound1 $(+ $kbound2)*)*,
|
||||||
|
V: Serialize,
|
||||||
|
$($typaram: $bound,)*
|
||||||
{
|
{
|
||||||
serializer.collect_map(self)
|
#[inline]
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.collect_seq(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<K, V> Serialize for BTreeMap<K, V>
|
map_impl!(BTreeMap<K: Ord, V>);
|
||||||
where
|
|
||||||
K: Serialize + Ord,
|
|
||||||
V: Serialize,
|
|
||||||
{
|
|
||||||
serialize_map!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<K, V, H> Serialize for HashMap<K, V, H>
|
map_impl!(HashMap<K: Eq + Hash, V, H: BuildHasher>);
|
||||||
where
|
|
||||||
K: Serialize + Eq + Hash,
|
|
||||||
V: Serialize,
|
|
||||||
H: BuildHasher,
|
|
||||||
{
|
|
||||||
serialize_map!();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user