diff --git a/src/header/mod.rs b/src/header/mod.rs index e84bf37e32..acd7ee9439 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -332,33 +332,10 @@ impl fmt::Debug for Headers { #[cfg(feature = "serde-serialization")] impl Serialize for Headers { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - struct HeadersVisitor<'a> { - iter: HeadersItems<'a>, - len: usize, - } - - impl<'a> ser::MapVisitor for HeadersVisitor<'a> { - fn visit(&mut self, serializer: &mut S) -> Result, S::Error> - where S: Serializer { - match self.iter.next() { - Some(header_item) => { - try!(serializer.visit_map_elt(header_item.name(), - header_item.value_string())); - Ok(Some(())) - } - None => Ok(None), - } - } - - fn len(&self) -> Option { - Some(self.len) - } - } - - serializer.visit_map(HeadersVisitor { - iter: self.iter(), - len: self.len(), - }) + serializer.visit_map(ser::impls::MapIteratorVisitor::new( + self.iter().map(|header| (header.name(), header.value_string())), + Some(self.len()), + )) } } diff --git a/src/http/mod.rs b/src/http/mod.rs index 0133bf25f8..396eec559d 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -23,7 +23,7 @@ pub struct RawStatus(pub u16, pub Cow<'static, str>); #[cfg(feature = "serde-serialization")] impl Serialize for RawStatus { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - (self.0, self.1.clone().into_owned()).serialize(serializer) + (self.0, &self.1).serialize(serializer) } }