Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Help needed with adding to the queue #322

Closed
Staninna opened this issue Jun 2, 2022 · 5 comments
Closed

Help needed with adding to the queue #322

Staninna opened this issue Jun 2, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Staninna
Copy link

Staninna commented Jun 2, 2022

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/git.luolix.top-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/git.luolix.top-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

@Staninna Staninna added bug Something isn't working help wanted Extra attention is needed labels Jun 2, 2022
@Staninna
Copy link
Author

Staninna commented 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/git.luolix.top-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

@marioortizmanero
Copy link
Collaborator

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.

@Staninna
Copy link
Author

Staninna commented 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

@marioortizmanero
Copy link
Collaborator

marioortizmanero commented 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.

@Staninna
Copy link
Author

Staninna commented 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

@Staninna Staninna closed this as completed Jun 2, 2022
Repository owner locked and limited conversation to collaborators Jul 22, 2022
@marioortizmanero marioortizmanero converted this issue into discussion #344 Jul 22, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants