mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #120] [CLOSED] Blocking module cleanup #257
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#257
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/120
Author: @marioortizmanero
Created: 8/29/2020
Status: ❌ Closed
Base:
master← Head:blocking-cleanup📝 Commits (10+)
e4f85f8First attempt with Derefd0e7a5fFormatting and Cargo.toml fix279c138Implemented run_blocking macro7532b3fFix tokio import for tests, small cleanupe783eaeImplemented macro for a single functiond3e821cNow with docs too9c783ddSingle impl block, documentation675aeb7More clear formatting578c13bApplied to all endpoints with a vim macro!2c29637Fixed docstrings📊 Changes
10 files changed (+1067 additions, -3146 deletions)
View changed files
📝
CHANGELOG.md(+2 -0)📝
Cargo.toml(+4 -2)📝
src/blocking/client.rs(+27 -1946)📝
src/blocking/mod.rs(+8 -0)📝
src/blocking/oauth2.rs(+66 -422)📝
src/blocking/util.rs(+28 -120)📝
src/client.rs(+846 -642)📝
src/lib.rs(+2 -0)➕
src/macros.rs(+70 -0)📝
src/oauth2.rs(+14 -14)📄 Description
This is a WIP implementation of #112.
It removes duplicated implementations in the blocking module. I've found three possible cases of how this implementation can be hidden, after creating a wrapper in the blocking module like so:
DerefandDerefMut. For example,rspotify::oauth2::SpotifyClientCredentials::is_token_expired. These will dereference the blocking wrapper into the original async struct, and call the async struct's method. These traits are automatically implemented with thederive_derefcrate, which is quite handy for our use case. This part avoids lots repetitive code but might cause issues with the typing system, since this dereference is only wanted to call the underlying type's methods. Thus, this case could be removed, writing the rest of the underlying methods like so:Self: if this was left toDeref, the method would return the underlying type, not the blocking wrapper type. For example,rspotify::blocking::Spotify::default. Thus, this requires to write the function signature again in the blocking module, along with some boilerplate code. This boilerplate code may vary, but it's usually got to do with the builder pattern, and looks something like this:rspotify::blocking::Spotify::search. This can be done in different ways, which is discussed in #112, but for this PR I used the simplest one for now:I'm not sure if the async -> sync conversion with the global runtime can be done automatically with a macro, because some of these methods have parameters, and I'm not sure how that would work in a macro. At most we could have one that does this:
Which is still an improvement. NOTE: this is now implemented in the
src/macros.rsfile.I still have to figure out if the documentation can be copied from the original method.
I only implemented the conversion for the
searchandmemethods inSpotifybecause I only wanted to show how I think it could be done. These can be tested with the available examples (as a note, themeexample doesn't work at all, but this might be because either the example or the original implementation are bugged, I'll have to look into it):What do you think?
TODO:
[#[doc(hidden)]?)client.rsoauth.rspub(in crate)fromSpotifyClientCredentialsandSpotifyOAuth🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.