You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a placeholder bug to track potentially converting the serialization api to use generators (#7746). Once we have generators, We'll be able to write a serializer like this:
struct A {
a: int,
b: B,
}
Struct B {
c: ~str,
d: ~[int],
}
impl serialize::Encodable for A {
fn encode_iter<'a>(&'a self) -> Option<Value<'a>> {
yield StructStart("A");
yield StructField("a", 0);
yield Int(self.a);
yield StructField("b", 1);
for value in self.b.encode_iter() { yield value; }
yield StructEnd;
}
}
impl serialize::Encodable for B {
fn encode_iter<'a>(&'a self) -> Option<Value<'a>> {
yield StructStart("B");
yield StructField("c", 0);
yield String(self.c);
yield StructField("d", 1);
for value in self.d.encode_iter() { yield value; }
yield StructEnd;
}
}
There are two advantages to this conversion. First, it's easier for rustc to optimize iterator-based code instead of recursive-closure-based code. Second, it allows for a serializer like extra::json::Encoder peek into the iterator stream to validate that a map key is actually a string. This would fix #8883.
The text was updated successfully, but these errors were encountered:
Generators aren't going to happen for a long time (if ever - it needs to make it through the RFC process), so I don't think it makes sense to have bugs tracking use cases. It would be better to collect this kind of information on a wiki or a etherpad.
This is a placeholder bug to track potentially converting the serialization api to use generators (#7746). Once we have generators, We'll be able to write a serializer like this:
A Deserializer would also be pretty simple:
There are two advantages to this conversion. First, it's easier for rustc to optimize iterator-based code instead of recursive-closure-based code. Second, it allows for a serializer like
extra::json::Encoder
peek into the iterator stream to validate that a map key is actually a string. This would fix #8883.The text was updated successfully, but these errors were encountered: