mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #244] [MERGED] Fix IDs v4 #335
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#335
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/244
Author: @marioortizmanero
Created: 8/30/2021
Status: ✅ Merged
Merged: 9/15/2021
Merged by: @marioortizmanero
Base:
master← Head:fix-ids-4📝 Commits (10+)
c2046c7Add UnknownId and some testsd5d2812Proper docs thanks to reworked macro5a52393Module-level documentation1ab8ad1Now with an example!3b66b9aStuck fighting compiler error about Deserialize5d459f4First draft with newtypeea435dbThe compiler hates mece0a860Mixing Attempt #1 and Attempt #2bbf0cc2Almost working now5b1562fFinally fix Offset impl📊 Changes
26 files changed (+719 additions, -535 deletions)
View changed files
📝
CHANGELOG.md(+6 -5)📝
examples/client_creds.rs(+3 -3)📝
examples/with_refresh_token.rs(+7 -7)📝
rspotify-model/src/album.rs(+6 -13)📝
rspotify-model/src/artist.rs(+4 -11)📝
rspotify-model/src/audio.rs(+6 -7)📝
rspotify-model/src/category.rs(+2 -2)📝
rspotify-model/src/context.rs(+7 -6)📝
rspotify-model/src/custom_serde.rs(+1 -1)📝
rspotify-model/src/idtypes.rs(+447 -217)📝
rspotify-model/src/lib.rs(+19 -18)📝
rspotify-model/src/offset.rs(+5 -7)📝
rspotify-model/src/playing.rs(+1 -2)📝
rspotify-model/src/playlist.rs(+4 -12)📝
rspotify-model/src/recommend.rs(+2 -2)📝
rspotify-model/src/search.rs(+5 -6)📝
rspotify-model/src/show.rs(+19 -28)📝
rspotify-model/src/track.rs(+6 -25)📝
rspotify-model/src/user.rs(+3 -10)📝
src/clients/base.rs(+4 -0)...and 6 more files
📄 Description
Description
I've finally understood what the Rust compiler was trying to tell me. This PR implements type-safe ID wrappers, it is the only way I've managed to do it. Everything is thoroughly explained in
rspotify-model/src/idtypes.rs, but if you have any questions please do let me know. In summary, I've ended up being able to makeIdan object-safe trait, so that it can be used asdyn Id. This way, it is possible to take e.g.Vec<dyn PlayableId>.This closes #203
Motivation and Context
Now that I've implemented it, the question is: are type-safe IDs worth it? There is currently a partial implementation of IDs in the
masterbranch in which I'm basing this PR. We have to either finish said implementation, or remove it completely in a different PR.Advantages:
TrackIdas a parameter makes it pretty clear what kind of ID is required, in comparison with&str, in which case it would have to be specified in the documentation (or by context).Id::uri,Id::url,Id::_typeFullTrackonly need anidfield;uriand_typecan be removed.Disadvantages:
endpoint(id)andendpoint(&TrackId::from_uri(id)?).Strings instead ofstr, which require an allocation. If this ends up being important in terms of performance, we could look into crates likesmol_str(which may not allocate until the string is longer than X bytes), or evenCow. So performance may not be that much of a problem; we can look into it in the future.Id::from_idwon't work anymore. This is only a disadvantage over the current implementation inmaster, not over not using type-safe IDs at all.Dependencies
Nothing new
Type of change
Please delete options that are not relevant.
Though it is a breaking change, the only breakage over master occurs when
Id::from_idand similars were used directly. Instead, a concrete type has to be provided now, likeArtistId::from_id. The other main breakage is in rspotify's model; some fields have been removed and modified so that they use this new feature instead of just strings. Additionally,IdBufhas been removed, since now it's always owned anyway.How Has This Been Tested?
There are new tests in
rspotify-model/src/idtypes.rs. Take a look in there. The previous tests still pass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.