fix doc bugs found by skeptic

This commit is contained in:
Oliver Schneider 2016-08-03 16:00:30 +02:00
parent e40b9e9814
commit 8c30ec9698
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46

View File

@ -434,35 +434,10 @@ impl serde::Serialize for Point {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer
{
serializer.serialize_struct("Point", PointMapVisitor {
value: self,
state: 0,
})
}
}
struct PointMapVisitor<'a> {
value: &'a Point,
state: u8,
}
impl<'a> serde::ser::MapVisitor for PointMapVisitor<'a> {
fn visit<S>(&mut self, serializer: &mut S) -> Result<Option<()>, S::Error>
where S: serde::Serializer
{
match self.state {
0 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt("x", &self.value.x))))
}
1 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt("y", &self.value.y))))
}
_ => {
Ok(None)
}
}
let mut state = try!(serializer.serialize_struct("Point", 2));
try!(serializer.serialize_struct_elt(&mut state, "x", &self.x));
try!(serializer.serialize_struct_elt(&mut state, "y", &self.y));
serializer.serialize_struct_end(state)
}
}