-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finish the pagination implementation #201
Conversation
&self, | ||
artist_id: &ArtistId, | ||
album_type: Option<AlbumType>, | ||
market: Option<Market>, | ||
market: Option<&Market>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had to make some parameters a reference, like Market
, because when using automatic pagination we iterate multiple times and would have to clone the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it makes sense. As I mentioned in another PR, it might be a chance to pass parameters by reference
&self, | ||
playlist_id: &PlaylistId, | ||
fields: Option<&str>, | ||
market: Option<&Market>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I was at it I made these parameters consistent; limit
and offset
always go last.
I've also tried to implement a macro for these but completely failed at doing so. It's really complicated with |
I've added a |
This should be ready for review now, @ramsayleung |
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-users-saved-albums) | ||
pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> + '_ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to have an anonymous lifetime annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, otherwise you get this:
Compiling rspotify v0.10.0 (/home/mario/Programming/rspotify)
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirem
ent
--> src/client.rs:1005:13
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> {
| ----- this data with an anonymous lifetime `'_`...
1004 | paginate(
1005 | move |limit, offset| self.current_user_saved_albums_manual(Some(limit), Some(offset)),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...is captured here...
|
note: ...and is required to live as long as `'static` here
--> src/client.rs:1003:48
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` l
ifetime bound
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> + '_ {
| ^^^^
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirem
ent
--> src/client.rs:1005:39
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> {
| ----- this data with an anonymous lifetime `'_`...
1004 | paginate(
1005 | move |limit, offset| self.current_user_saved_albums_manual(Some(limit), Some(offset)),
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> src/client.rs:1003:48
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` l
ifetime bound
|
1003 | pub fn current_user_saved_albums(&self) -> impl Paginator<ClientResult<SavedAlbum>> + '_ {
| ^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0759`.
error: could not compile `rspotify`
To learn more, run the command again with --verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, but I can remove it from the paginate
function. Give me a sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The self
has an anonymous lifetime '_
, in order to explicitly indicate the return value has can live as long as the self
, so we just simply add an '_
for the return value? is it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, the thing is that paginate
captures self
, which has a borrowed lifetime of '_
. Thus, we must indicate that the returned value won't outlive self
with + '_
. I thought this was done automatically by the compiler but being an impl
it makes sense that it's forcing us to specify the lifetime.
Beside the small nitpicks I commented, everything else looks good to me. And I think it's ready to merge :) |
Ok @ramsayleung I've relaxed the lifetimes as much as possible and the tests have passed. Take a look and merge if you're ok with this PR then. |
Merged :) |
Thanks for picking this up while I was busy/distracted! |
No problem! If you have any concerns/suggestions about the implementation details, do let us know :) |
Thanks @icewind1991 and @marioortizmanero again for your great works :) I just wrote a post to demonstrate this brilliant feature and how it works https://0x709394.me/Let's-make%20everything%20iterable |
Great! I didn't know you had a blog, saved it. I plan on making one myself when we finally release 0.11 at https://nullderef.com :D I enjoyed it, very visual. A few comments:
|
Yep, we are stepping forward to v0.11. If you don't mind, I would like to add your blog to my blogroll :)
Oooh, Great catch, thanks for your heads-up. |
Cool! I don't have one yet but I'll definitely add you too when I do :) |
Description
This finishes what was left at #166
Closes #124