json icon indicating copy to clipboard operation
json copied to clipboard

Document behavior of to_pretty_string when passing Value

Open marcospb19 opened this issue 4 years ago • 1 comments
trafficstars

From https://docs.rs/serde_json/1.0.68/serde_json/fn.to_string_pretty.html:

image

I assume that if I call

use serde_json::*;
to_string_pretty<Value>(...);

I can .unwrap() this result safely, is it right? Or Value's implementation of Serialize might decide to fail?

If it's the former, can I make a PR adding this piece of info to this doc page?

marcospb19 avatar Sep 16 '21 16:09 marcospb19

Looking at the source code, it seems Value's Serialize impl indeed cannot fail:

https://github.com/serde-rs/json/blob/931ee23b1abf6b302df7c20a3a5866bf1a8a33ca/src/value/ser.rs#L13-L36

I think a PR to state this in the docs is a good idea, although the docs should be added to Value, not to_string_pretty.

kangalio avatar May 23 '23 18:05 kangalio