Cerber-Ursi/uneval

Empty Vecs within a parent struct are serialized incorrectly

alokedesai opened this issue · 1 comments

Consider a struct like follows:

struct Foo {
  bar: Vec<String>,
  bazz: String
}

If I have an instance of Foo that looks like:

Foo {
   bar: vec![],
   bazz: "some val".into()
}

uneval will serialize this incorrectly and produce something along the lines of:

Foo {
   bar: Vector::new().into_iter().collect()
   bazz: "some val".to_string()
}

Note how there's no comma between bar and bazz. From looking at the code this seems to be because we have a nested vector within a struct, which means when we try to serialize the sequence, we reset the value of inside to false (via the call to start_sub). Since there are no items within the vector, it never gets set to true--which means we try to serialize the next field (in this case, bazz) no comma is added, because inside is still false.

I think the right solution here is to cache the value of inside before calling start_sub. When we finish serializing within the following of Serialize for SerializeSeq, SerializeTuple, SerializeTupleStruct, SerializeTupleVariant, SerializeMap, SerializeStruct, SerializeStructVariant we reset inside back to the cached value.

Thanks for notifying! Fixed in 0.2.3, published just now.