mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 11:21:01 +00:00
More like the Deserialize impls for sequences
This commit is contained in:
+29
-49
@@ -152,72 +152,52 @@ array_impls!(01 02 03 04 05 06 07 08 09 10
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! serialize_seq {
|
|
||||||
() => {
|
|
||||||
#[inline]
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where S: Serializer,
|
|
||||||
{
|
|
||||||
serializer.collect_seq(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Serialize for [T]
|
impl<T> Serialize for [T]
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
serialize_seq!();
|
#[inline]
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
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<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
|
||||||
|
where
|
||||||
|
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
|
||||||
|
$($typaram: $bound1 $(+ $bound2)*)*
|
||||||
|
{
|
||||||
|
#[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<T> Serialize for BinaryHeap<T>
|
seq_impl!(BinaryHeap<T: Ord>);
|
||||||
where
|
|
||||||
T: Serialize + Ord,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<T> Serialize for BTreeSet<T>
|
seq_impl!(BTreeSet<T: Ord>);
|
||||||
where
|
|
||||||
T: Serialize + Ord,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T, H> Serialize for HashSet<T, H>
|
seq_impl!(HashSet<T: Eq + Hash, H: BuildHasher>);
|
||||||
where
|
|
||||||
T: Serialize + Eq + Hash,
|
|
||||||
H: BuildHasher,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<T> Serialize for LinkedList<T>
|
seq_impl!(LinkedList<T>);
|
||||||
where
|
|
||||||
T: Serialize,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<T> Serialize for Vec<T>
|
seq_impl!(Vec<T>);
|
||||||
where
|
|
||||||
T: Serialize,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<T> Serialize for VecDeque<T>
|
seq_impl!(VecDeque<T>);
|
||||||
where
|
|
||||||
T: Serialize,
|
|
||||||
{
|
|
||||||
serialize_seq!();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user