serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.7k stars 536 forks source link

Change serde_json::from_value to use pass-by-reference #1128

Open rooney opened 2 months ago

rooney commented 2 months ago

If the function needs ownership, you should pass by value. If the function only needs a reference, you should pass by reference.

-- https://stackoverflow.com/a/64814149/342293

from_value doesn't need to own its parameter, so it should use pass-by-reference.

GnomedDev commented 1 month ago

Is this not an obvious breaking change that would require a serde_json 2.0?

rooney commented 1 month ago

Is this not an obvious breaking change that would require a serde_json 2.0?

Hmm yes, any other parts that should also been updated? (Apologies if these should be obvious, still learning)

rooney commented 3 weeks ago

@GnomedDev Redone the fix so now from_value accepts both &Value and Value (so no breaking changes, but maybe the latter can be deprecated?). New test for the &Value is on doctest (should I add more?)