Replies: 2 comments 10 replies
-
I haven't been thinking about this, to be honest. Initially, the project was born under the idea of "having at least something", so all the architectural decisions weren't very mature and well-thought for 3rd-party usage. You're raising great points. I think for now, it's ok to stick with returning the raw objects, as well as adding/removing |
Beta Was this translation helpful? Give feedback.
-
Raising this again since as you can see from #567 I hit a few more field errors. They're both fields that I don't care about but because my Plex server presented them in a different format to that which we expect deserialization fails for the entire struct and so made certain items in my library unusable. I think it would be better for this crate to fail softly in the case of most fields failing to deserialize. What do you think to making it so fields that are wrapped in an I'd be happy to work on implementing this if you think it makes sense. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking a little on two different but related issues that I see with this crate as it stands. I would be interested if you have thoughts @andrey-yantsen or if this is even a problem you care about before I consider tinkering with any potential solutions.
The first problem is that the Plex REST API is sort of painful. We have fields that in some API calls are returned as numbers but returned as strings in others (aside: I'm pretty sure this is because the API used to be XML only which has no notion of numbers as such and whatever they've done to support JSON isn't entirely correct or complete). We have objects that seem like they are the same type when returned from different API calls but one call may return a bunch of additional fields compared to another. So far this is resolved by liberal usage of
Option
for fields and guessing at a fields expected type and converting accordingly.The second problem is that right now there isn't a much of a public API that we expose to abstract away from the innards of Plex, other than a couple of things we just give direct access to the deserialized structs. That's fine, particularly right now it gives a lot of flexibility for playing around. But when combined with the above issue what it leaves us with is an exposed API that can be awkward to use (liberal need to check or unwrap
Option
) and needing to break API almost every time a new API call is implemented (the patch I'm working on right now is forced to convert yet more fields toOption
).One thing that could be done to reduce the usage of
Option
would be to deserialize to different structs for different API calls, even different structs for different media types. In this way only the fields known to be possible for a given "thing" are present. That could be a vast explosion in the number of structs though I think there are tricks we could do with macros and such to re-use groups of fields across them.Though a totally reasonable thing to say to this is that this is all as it should be, this is a low-level crate with the intent of doing minimal wrapping to make Plex Rust accessible and safe. Other crates can be built on top of this to make a nice high-level abstraction as folks desire. Better to expose all the guts so they have everything they could need.
Have you had any thoughts along these lines?
Beta Was this translation helpful? Give feedback.
All reactions