Skip to content
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

stringify takes ownership instead of a reference #87

Closed
meh opened this issue Aug 6, 2016 · 8 comments
Closed

stringify takes ownership instead of a reference #87

meh opened this issue Aug 6, 2016 · 8 comments

Comments

@meh
Copy link

meh commented Aug 6, 2016

Is there a reason it takes the JsonValue by value instead of by reference?

I have a Cache that contains a JsonValue which is updated in place, and every once in a while it saves it to disk as JSON, so currently I have to clone the object which sounds like an artificial requirement.

Other than the obvious loss of the nice json::stringify(2) and friends, I think it would be a win performance wise (at least for my case 🐼)

@meh
Copy link
Author

meh commented Aug 6, 2016

Actually I'm partially dumb, there are JsonValue::dump and JsonValue::to_writer which kind of fit my need, but I want it to be pretty printed.

@meh
Copy link
Author

meh commented Aug 6, 2016

On a tangential note to_writer should probably return an io::Result otherwise I have no way to know if the write was successful.

@meh
Copy link
Author

meh commented Aug 6, 2016

Ok, I'm fully dumb and apparently also blind, there is JsonValue::pretty, except I want a to_writer that returns an io::Result and has an option to pretty print 🐼

Sorry for the stream of notifications.

@dtolnay
Copy link

dtolnay commented Aug 6, 2016

On a tangential note to_writer should probably return an io::Result otherwise I have no way to know if the write was successful.

This is a separate issue (:+1: by the way) so I filed #88 to follow up.

@dtolnay
Copy link

dtolnay commented Aug 6, 2016

Actually I'm partially dumb, there are JsonValue::dump and JsonValue::to_writer which kind of fit my need, but I want it to be pretty printed.

I filed #89 for pretty print to writer.

@meh
Copy link
Author

meh commented Aug 6, 2016

I'll close this because since there are JsonValue::dump and JsonValue::pretty having stringify do the magical Into<JsonValue> makes a ton of sense.

@meh meh closed this as completed Aug 6, 2016
@dtolnay
Copy link

dtolnay commented Aug 6, 2016

Until these are fixed, if you are stuck there is always serde_json::to_writer_pretty which (1) takes a reference, (2) writes to a writer (3) prettily, and (4) returns the error 😉.

@maciejhirsz
Copy link
Owner

maciejhirsz commented Aug 11, 2016

Sorry this took so long, been pretty busy lately, fixed with #88 and #89 (Thanks @dtolnay!)

Might need to mention in the docs for stringify that there are alternative ways to write things.

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

No branches or pull requests

3 participants