Use serialize_seq! to implement Serialize for [T]

This commit is contained in:
Anthony Ramine 2017-02-04 12:21:45 +01:00
parent 30b8036efa
commit 763ab9c2a1

View File

@ -144,24 +144,6 @@ impl<T> Serialize for PhantomData<T> {
}
}
///////////////////////////////////////////////////////////////////////////////
impl<T> Serialize for [T]
where T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,
{
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
for e in self {
try!(seq.serialize_element(e));
}
seq.end()
}
}
///////////////////////////////////////////////////////////////////////////////
macro_rules! array_impls {
@ -232,6 +214,12 @@ macro_rules! serialize_seq {
}
}
impl<T> Serialize for [T]
where T: Serialize,
{
serialize_seq!();
}
#[cfg(any(feature = "std", feature = "collections"))]
impl<T> Serialize for BinaryHeap<T>
where T: Serialize + Ord