You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm starting to notice a pattern of many major libraries creating a Json<T> struct, and then they are all incompatible. Everything else works together nicely, but not this one item-- and working around it seems like not 'Rusty' unnecessary code bloat.
Usage example: data comes in from rocket web server and then gets saved with sqlx. Your only solution seems to be to use some custom adaptor approach. It gets really ugly as you move to libraries built on these base libraries.
You also end up with some other libs following other patterns that lose typing of the underlying structure. I believe a simple Json structure inside of the main lib would be good for the Rust community by allowing other libs to implement around that standard and thus leading to interoperability with this as the common interface.
What are your thoughts? Am I so lucky that there is a solution I'm missing?
The text was updated successfully, but these errors were encountered:
The Rust standard library is supposed to be small in order not to be tempted to introduce non-backward-compatible changes. You will probably never see a struct named Json in an std lib that doesn't provide a way to generate random numbers.
As to why things are like that, it's simply because these kinds of structs are actually needed to provide the nice API of these 3 crates.
Take rocket. Json<T> needs to implement FromRequest and Responder. You can't just implement FromRequest for any deserializable trait because JSON is not the only deserialization method that exists, and because a lot of other FromRequest types do implement Deserialize but that's not how they should be build in a FromRequest context. By introducing a wrapper type, all these ambiguities are solved.
And honestly, I don't understand why you call this a "code bloat". These 3 structures all have one field and will probably be implemented transparently like T in RAM. Converting from one to the other has literally no cost.
I'm starting to notice a pattern of many major libraries creating a
Json<T> struct
, and then they are all incompatible. Everything else works together nicely, but not this one item-- and working around it seems like not 'Rusty' unnecessary code bloat.Examples:
Usage example: data comes in from rocket web server and then gets saved with sqlx. Your only solution seems to be to use some custom adaptor approach. It gets really ugly as you move to libraries built on these base libraries.
You also end up with some other libs following other patterns that lose typing of the underlying structure. I believe a simple Json structure inside of the main lib would be good for the Rust community by allowing other libs to implement around that standard and thus leading to interoperability with this as the common interface.
What are your thoughts? Am I so lucky that there is a solution I'm missing?
The text was updated successfully, but these errors were encountered: