[GH-ISSUE #322] Help needed with adding to the queue #102

Closed
opened 2026-02-27 20:23:07 +03:00 by kerem · 5 comments
Owner

Originally created by @Staninna on GitHub (Jun 2, 2022).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/322

Not really a bug but more a question for help.

I am trying to put a song in the queue and then play it after 35 seconds skip it and repeat.
but I get errors I'm stuck on this for a few days now and it is really demotivating.
I hope I don't break any rules I just need a little help.

Reposetory
File in question

my code


fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>())
}

let current_track = tracks.pop();
let track_id = current_track.as_ref().unwrap().track.as_ref().unwrap().id();

print_type_of(&current_track);
// Output: core::option::Option<rspotify_model::playlist::PlaylistItem>
print_type_of(&track_id);
// Output: &core::option::Option<&dyn rspotify_model::idtypes::PlayableId>
print_type_of(&client);
// Output: rspotify::auth_code::AuthCodeSpotify

// My problem
&client.add_item_to_queue(track_id.unwrap(), Some(device_id.unwrap().as_str()));

Errors I get

error[E0277]: the size for values of type `dyn PlayableId` cannot be known at compilation time
    --> src/main.rs:168:21
     |
168  |             &client.add_item_to_queue(track_id.unwrap(), Some(device_id.unwrap().as_str()));
     |                     ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
     |
     = help: the trait `Sized` is not implemented for `dyn PlayableId`
note: required by a bound in `add_item_to_queue`
    --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:32
     |
1221 |     async fn add_item_to_queue<T: PlayableId>(
     |                                ^ required by this bound in `add_item_to_queue`

Not in the current state of the repo but in this statehttps://pastebin.com/bjdXZyTz

error[E0277]: the trait bound `&dyn PlayableId: PlayableId` is not satisfied
    --> src/main.rs:164:20
     |
164  |             client.add_item_to_queue(&track_id.unwrap(), None);
     |                    ^^^^^^^^^^^^^^^^^ the trait `PlayableId` is not implemented for `&dyn PlayableId`
     |
     = help: the following other types implement trait `PlayableId`:
               EpisodeId
               TrackId
note: required by a bound in `add_item_to_queue`
    --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:35
     |
1221 |     async fn add_item_to_queue<T: PlayableId>(
     |                                   ^^^^^^^^^^ required by this bound in `add_item_to_queue`

I am pretty new to rust

Originally created by @Staninna on GitHub (Jun 2, 2022). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/322 Not really a bug but more a question for help. I am trying to put a song in the queue and then play it after 35 seconds skip it and repeat. but I get errors I'm stuck on this for a few days now and it is really demotivating. I hope I don't break any rules I just need a little help. [Reposetory](https://github.com/staninna/spotiakf-v2) [File in question](https://github.com/Staninna/SpotiAFK-v2/blob/master/src/main.rs#L161-L172) my code ```rs fn print_type_of<T>(_: &T) { println!("{}", std::any::type_name::<T>()) } let current_track = tracks.pop(); let track_id = current_track.as_ref().unwrap().track.as_ref().unwrap().id(); print_type_of(&current_track); // Output: core::option::Option<rspotify_model::playlist::PlaylistItem> print_type_of(&track_id); // Output: &core::option::Option<&dyn rspotify_model::idtypes::PlayableId> print_type_of(&client); // Output: rspotify::auth_code::AuthCodeSpotify // My problem &client.add_item_to_queue(track_id.unwrap(), Some(device_id.unwrap().as_str())); ``` Errors I get ``` error[E0277]: the size for values of type `dyn PlayableId` cannot be known at compilation time --> src/main.rs:168:21 | 168 | &client.add_item_to_queue(track_id.unwrap(), Some(device_id.unwrap().as_str())); | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn PlayableId` note: required by a bound in `add_item_to_queue` --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:32 | 1221 | async fn add_item_to_queue<T: PlayableId>( | ^ required by this bound in `add_item_to_queue` ``` Not in the current state of the repo but in [this state]()https://pastebin.com/bjdXZyTz ``` error[E0277]: the trait bound `&dyn PlayableId: PlayableId` is not satisfied --> src/main.rs:164:20 | 164 | client.add_item_to_queue(&track_id.unwrap(), None); | ^^^^^^^^^^^^^^^^^ the trait `PlayableId` is not implemented for `&dyn PlayableId` | = help: the following other types implement trait `PlayableId`: EpisodeId TrackId note: required by a bound in `add_item_to_queue` --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:35 | 1221 | async fn add_item_to_queue<T: PlayableId>( | ^^^^^^^^^^ required by this bound in `add_item_to_queue` ``` I am pretty new to rust
kerem 2026-02-27 20:23:07 +03:00
Author
Owner

@Staninna commented on GitHub (Jun 2, 2022):

If I add a reference to track_id.unwrap() when I call add_items_to_queue i get another error that I edited into the OP but I will put it here too

code

let current_track = tracks.pop();
let track_id = current_track.unwrap().track.unwrap().id();
client.add_item_to_queue(&track_id.unwrap(), None);

Error

error[E0277]: the trait bound `&dyn PlayableId: PlayableId` is not satisfied
    --> src/main.rs:164:20
     |
164  |             client.add_item_to_queue(&track_id.unwrap(), None);
     |                    ^^^^^^^^^^^^^^^^^ the trait `PlayableId` is not implemented for `&dyn PlayableId`
     |
     = help: the following other types implement trait `PlayableId`:
               EpisodeId
               TrackId
note: required by a bound in `add_item_to_queue`
    --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:35
     |
1221 |     async fn add_item_to_queue<T: PlayableId>(
     |                                   ^^^^^^^^^^ required by this bound in `add_item_to_queue`

I also updated the repo if that is any helpful to you with those 3 lines of code

<!-- gh-comment-id:1144972606 --> @Staninna commented on GitHub (Jun 2, 2022): If I add a reference to `track_id.unwrap()` when I call `add_items_to_queue` i get another error that I edited into the OP but I will put it here too code ```rs let current_track = tracks.pop(); let track_id = current_track.unwrap().track.unwrap().id(); client.add_item_to_queue(&track_id.unwrap(), None); ``` Error ``` error[E0277]: the trait bound `&dyn PlayableId: PlayableId` is not satisfied --> src/main.rs:164:20 | 164 | client.add_item_to_queue(&track_id.unwrap(), None); | ^^^^^^^^^^^^^^^^^ the trait `PlayableId` is not implemented for `&dyn PlayableId` | = help: the following other types implement trait `PlayableId`: EpisodeId TrackId note: required by a bound in `add_item_to_queue` --> /home/stan/.cargo/registry/src/github.com-1ecc6299db9ec823/rspotify-0.11.5/src/clients/oauth.rs:1221:35 | 1221 | async fn add_item_to_queue<T: PlayableId>( | ^^^^^^^^^^ required by this bound in `add_item_to_queue` ``` I also updated the repo if that is any helpful to you with those 3 lines of code
Author
Owner

@marioortizmanero commented on GitHub (Jun 2, 2022):

Ah sorry, I removed my comment because I had misread it. It looks like the repository you shared is private and I can't see the files.

Also, it looks like you want to return a Result so that you can avoid so many unwraps with the ? operator instead.

This will probably become a bit easier to use after #305 is merged and released in the next version. Maybe you should try with that? I'll try to bump it soon.

<!-- gh-comment-id:1144973524 --> @marioortizmanero commented on GitHub (Jun 2, 2022): Ah sorry, I removed my comment because I had misread it. It looks like the repository you shared is private and I can't see the files. Also, it looks like you want to return a `Result` so that you can avoid so many `unwraps` with the `?` operator instead. This will probably become a bit easier to use after #305 is merged and released in the next version. Maybe you should try with that? I'll try to bump it soon.
Author
Owner

@Staninna commented on GitHub (Jun 2, 2022):

It looks like the repository you shared is private and I can't see the files.

Sorry I made it public now

And I tried lots of different things with the track_id but I don't understand what it is supposed to be I know it would be this but I don't know what it is

Maybe I have to put a hold on this project and revisit it when #305 is merged

<!-- gh-comment-id:1144987431 --> @Staninna commented on GitHub (Jun 2, 2022): > It looks like the repository you shared is private and I can't see the files. Sorry I made it public now And I tried lots of different things with the `track_id` but I don't understand what it is supposed to be I know it would be [this](https://docs.rs/rspotify/latest/rspotify/clients/oauth/trait.OAuthClient.html#method.add_item_to_queue) but I don't know what it is Maybe I have to put a hold on this project and revisit it when #305 is merged
Author
Owner

@marioortizmanero commented on GitHub (Jun 2, 2022):

Yeah I think that's not possible until #305, sorry for the inconveniences! &dyn Trait doesn't implement Trait, only dyn Trait does. However, the function asks for a &Trait, so it's impossible to have both.

We'll try to get it merged this/next week and I'll ping you to get some feedback.

<!-- gh-comment-id:1144996505 --> @marioortizmanero commented on GitHub (Jun 2, 2022): Yeah I think that's not possible until #305, sorry for the inconveniences! `&dyn Trait` doesn't implement `Trait`, only `dyn Trait` does. However, the function asks for a `&Trait`, so it's impossible to have both. We'll try to get it merged this/next week and I'll ping you to get some feedback.
Author
Owner

@Staninna commented on GitHub (Jun 2, 2022):

It is okay I will wait till #305 gets merged don't rush it I got plenty of other things to do

Thanks for your quick support

<!-- gh-comment-id:1145059496 --> @Staninna commented on GitHub (Jun 2, 2022): It is okay I will wait till #305 gets merged don't rush it I got plenty of other things to do Thanks for your quick support
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#102
No description provided.