-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extra::json doesn't support using Encodable to encode straight to a json value #8335
Comments
Yes, this struck me as very weird |
Triage bump |
So, I started to work on this, trying to do something like this: impl <A:Encodable> ToJson for A {
fn to_json(&self) -> ~Json {
ToJsonEncoder::new().json_encode(self)
}
}
struct ToJsonEncoder {
// ...
}
impl serialize::Encoder for ToJsonEncoder {
// ...
} The For instance: struct Foo {
bar: ~str,
baz: uint
}
impl<E: Encoder> Encodable<E> for Foo {
fn encode(&self, e: &mut E) {
e.emit_str(self.bar);
e.emit_uint(self.baz);
}
} This This leaves me wondering if |
cc @nick29581, could this move to rust-lang/rustc-serialize? |
This issue has been moved to the rustc-serialize repo: rust-lang-deprecated/rustc-serialize#46 |
If one wants to convert an
Encodable
type to aJson
value, then one has to do something like (i.e. encode as JSON to a string and then parse that string):The text was updated successfully, but these errors were encountered: