Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Simplify serialize_seq and serialize_map implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 13, 2016
1 parent 01d8fc4 commit 71771bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions yaml/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ impl<'a> ser::Serializer for Serializer<'a> {
Some(len) => yaml::Array::with_capacity(len),
};
*self.doc = Yaml::Array(vec);
let mut elt_ser = Serializer::new(self.doc);
while try!(visitor.visit(&mut elt_ser)).is_some() {
while try!(visitor.visit(self)).is_some() {
}
Ok(())
}
Expand All @@ -105,8 +104,7 @@ impl<'a> ser::Serializer for Serializer<'a> {
where V: ser::MapVisitor,
{
*self.doc = Yaml::Hash(yaml::Hash::new());
let mut elt_ser = Serializer::new(self.doc);
while try!(visitor.visit(&mut elt_ser)).is_some() {
while try!(visitor.visit(self)).is_some() {
}
Ok(())
}
Expand Down
19 changes: 19 additions & 0 deletions yaml_tests/tests/test_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ fn test_basic_struct() {
test_serde(thing, yaml);
}

#[test]
fn test_nested_vec() {
let thing = vec![
vec![1, 2, 3],
vec![4, 5, 6],
];
let yaml = indoc!("
---
-
- 1
- 2
- 3
-
- 4
- 5
- 6");
test_serde(thing, yaml);
}

#[test]
fn test_nested_struct() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down

0 comments on commit 71771bf

Please sign in to comment.