Closed Spanfile closed 2 years ago
Hey, thanks for the contribution!
Yes, you're completely right. I think I didn't end up doing this back then because it just felt weird to do spotify.prompt_for_token
without it being mutable. The user could think that said function actually doesn't modify the internal token.
But it doesn't make sense to keep it mutable because it disallows concurrency, so we should definitely merge this. You'll need to update the tests and examples, though, as mut
is used in many other places.
Thank you for your feedback. I've gone ahead and removed all unnecessary mut
s in the examples.
Merging this! Thanks again.
Description
OAuthClient::request_token
takes self as&mut
, yet all of its implementors are designed for an async environment, where inner mutability for their fields is required throughArc<Mutex<_>>
, as is the case for the token fields, thus self doesn't actually have to be a mutable reference. By making the reference immutable, it is much more comfortable to use the clients in application code, since there's no need to wrap them in e.g. a Mutex or an RwLock only for the one case where a mutable self is needlessly required.However,
AuthCodePkceSpotify::get_authorize_url
is still left as is to take self as&mut
since it has to set itsverifier
field, and converting that field toArc<Mutex<_>>
and converting the function intoasync
would be a breaking change, hence I've left it out of this PR.Motivation and Context
I've been using the library recently and ran into this ergonomics issue.
Dependencies
None.
Type of change
How has this been tested?
The crate test suite ran succesfully. I removed one unneeded
mut
intests/test_with_credential.rs
.Is this change properly documented?
I'm unsure if this is a breaking change, since existing application code will still work, it would just be beneficial for them to adapt to not requiring mutability anymore. If someone has implemented
OAuthClient
for their own type, though, it will be a breaking change since the trait signature has changed.