InputUsername / listenbrainz-rs

ListenBrainz API bindings for Rust
https://crates.io/crates/listenbrainz
MIT License
12 stars 6 forks source link

Add more derives on the models #21

Open RustyNova016 opened 7 months ago

RustyNova016 commented 7 months ago

I noticed that a lot of the models lack the classic Clone, PartialEq, Eq combo that most API do implement. Is this intentional? I could see having use cases for those derives, expecialy Clone.

I can do a pull request, but I do want to know whether I should do it before wasting my time.

shymega commented 7 months ago

So, Clone trait would probably be OK. But for structs, I wouldn't include traits PartialEq and Eq. For enums, that's fine. Go for it in terms of enums.

InputUsername commented 7 months ago

:+1: Clone would be nice to have, not sure about the added benefit of PartialEq/Eq

shymega commented 7 months ago

The benefits of PartialEq/Eq for enums in particular would allow for conditionals to work. Such as if response == ResponseType::Whatever { /* do something */.

As is my understanding.

RustyNova016 commented 7 months ago

PartialEq/Eq would work awesomely for request caching without needing to use a costly hash and/or creating your own struct. Like I can imagine an app that has a vector of listens that hold all of the user's listens, then periodically send a request to fetch new ones. If the request return the same listen, don't reinsert it. If not, insert.

Its also not costing any runtime cost as it would be tree shaken if unused.