Json: serde_json::Error ought to derive a few more traits

Created on 19 Jun 2017  路  4Comments  路  Source: serde-rs/json

At the very least, it would be great if serde_json::Error derived Clone. Eq and PartialEq would be nice bonuses. This would make the library more ergonomic and improve testability as it allows a direct comparison of expected errors. Clone would be nice if a serialization error needs to get passed to more than one thread across a channel.

never mind

Most helpful comment

@dtolnay

+1 for the case. Lack of Clone implementation pushes developers to use .to_string() ending up with stringly-typed opaque errors.

All 4 comments

Hmm, well, it looks like even the std library error types generally don't provide Clone. I'll just close this and go write newtype wrappers.

I'd like to request that this issue be re-opened. Without deriving PartialEq its impossible to test using asserrt_eq!. What's the best way to test code that uses serde_json internally?

@dtolnay I'd also like this to be reconsidered. In ruma-events, I currently have to .to_string() json errors because I want structs that indirectly contain them to implement Clone.

@dtolnay

+1 for the case. Lack of Clone implementation pushes developers to use .to_string() ending up with stringly-typed opaque errors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

allan-simon picture allan-simon  路  6Comments

dtolnay picture dtolnay  路  3Comments

vityafx picture vityafx  路  6Comments

dtolnay picture dtolnay  路  6Comments

chanks picture chanks  路  5Comments