Converted serde serialization to new style

This commit is contained in:
Andrew Dudney 2016-08-23 12:23:07 -06:00
parent 753609918e
commit f43e2e13c7

View file

@ -197,41 +197,11 @@ mod eders_ser {
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("Decomposed", DecomposedVisitor { let mut state = try!(serializer.serialize_struct("Decomposed", 3));
value: self, try!(serializer.serialize_struct_elt(&mut state, "scale", &self.scale));
state: 0, try!(serializer.serialize_struct_elt(&mut state, "rot", &self.rot));
}) try!(serializer.serialize_struct_elt(&mut state, "disp", &self.disp));
} serializer.serialize_struct_end(state)
}
struct DecomposedVisitor<'a, V: 'a + VectorSpace, R: 'a> {
value: &'a Decomposed<V, R>,
state: u8,
}
impl<'a, V: 'a + VectorSpace, R> serde::ser::MapVisitor for DecomposedVisitor<'a, V, R>
where V: Serialize, V::Scalar: Serialize, R: Serialize
{
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("scale", &self.value.scale))))
},
1 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt("rot", &self.value.rot))))
},
2 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt("disp", &self.value.disp))))
},
_ => {
Ok(None)
},
}
} }
} }
} }