mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 15:25:38 +00:00
fix doc bugs found by skeptic
This commit is contained in:
parent
e40b9e9814
commit
8c30ec9698
33
README.md
33
README.md
@ -434,35 +434,10 @@ impl serde::Serialize for Point {
|
|||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: serde::Serializer
|
where S: serde::Serializer
|
||||||
{
|
{
|
||||||
serializer.serialize_struct("Point", PointMapVisitor {
|
let mut state = try!(serializer.serialize_struct("Point", 2));
|
||||||
value: self,
|
try!(serializer.serialize_struct_elt(&mut state, "x", &self.x));
|
||||||
state: 0,
|
try!(serializer.serialize_struct_elt(&mut state, "y", &self.y));
|
||||||
})
|
serializer.serialize_struct_end(state)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user