Replies: 8 comments
-
Let take a glance at the function signature of /// Note that the token is wrapped by a `Mutex` in order to allow interior
/// mutability. This is required so that the entire client doesn't have to
/// be mutable (the token is accessed to from every endpoint).
fn get_token(&self) -> Arc<Mutex<Option<Token>>>; If we choose to use Then, there are two options come to our mind, the first and most straight forward one, change the function signature But the problem is that we need to surface this mutability to the library users, all existing code and packages which depend on rspotify need to update their declaration from: let rspotify = xxxx..
// to
let mut rspotify = xxx. It means we break the all backward compatibility, even though rspotify hasn't released the 1.0 version, but we want to minimize the breaking changes. The second option is to impose interior mutability, with |
Beta Was this translation helpful? Give feedback.
-
Oh yes, that is of course the right path for backwards compatibility, but I saw it used to be |
Beta Was this translation helpful? Give feedback.
-
Yes, because in the past, we only read the token value from But when we wanted to implement the automatic re-authentication feature, this problem surfaced to us: #4 |
Beta Was this translation helpful? Give feedback.
-
Yup, I've (partly) read through that issue before, but I don't understand this:
Why is that an issue? Why not just have a mutable client? There might be something obvious I'm not seeing. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
As I've already mentioned before, at the beginning, the Then, we would like to implement re-authentication feature, which required to modify the
This is how the |
Beta Was this translation helpful? Give feedback.
-
Ah, I see I didn't understand the issue fully. I didn't cosider the fact that a mutable client would break backwards compatibility, my bad. Thanks for clearing it up! |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm working on a similar project and was wondering why rspotify uses an
Arc<Mutex<Option<Token>>>
, instead of just anOption<Token>
.I've read the note from the
get_token
method, but I don't quite understand why the entire client could just be mutable. Isn't a Mutex unnecessary unless the token is being accessed from separate threads?Beta Was this translation helpful? Give feedback.
All reactions