Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

serialize::json is encouraging allocating intermediate buffers #57

Closed
steveklabnik opened this issue Feb 15, 2015 · 2 comments
Closed

Comments

@steveklabnik
Copy link
Contributor

Issue by huonw
Tuesday Jul 01, 2014 at 23:58 GMT

For earlier discussion, see rust-lang/rust#15317

This issue was labelled with: A-libs in the Rust repository


The Encodable/Decodable interface is designed to avoid having to allocate everything to intermediate buffers, but json is encouraging going via String. serialize::json has the top level encode function returning a String, and all the examples use encode directly, there's no demonstration of the good direct-to-Writer API.

That is, something like

println!("{}", json::encode(&x))

can be written a little like

encodable.encode(&mut json::Encoder::new(&mut io::stdout()))

If that is deemed too ugly, I think we should work on fixing the ergonomics of the good version, rather than just leaping straight to the -> String ones (e.g. json::encode(&mut io::stdout(), &x) would be nice, and work with json::encode(&mut some_file, &x), json::encode(&mut some_tcp_stream, &x), etc.).

cc @aturon

@oli-obk
Copy link
Contributor

oli-obk commented Feb 26, 2015

For decoding the entire source iterator is consumed, everything is converted to Json objects, and then decoded to the final type, dropping the Json objects.

@alexcrichton
Copy link
Contributor

I'm going to close this now that this crate is deprecated in favor of serde. We're discontinuing feature development in rustc-serialize but will still continue to merge bug fixes if they arise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants