twitch-rs / twitch_api

Rust library for talking with the Twitch API aka. "Helix", TMI and more! Use Twitch endpoints fearlessly!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update to reqwest 0.12 make error "trait `twitch_api::HttpClient` is not implemented for `reqwest::Client`"

Nakuromi opened this issue · comments

Hi,

I have a compilation error with my code when in dependecy, I update reqwest from 0.11.* to 0.12.*.
This is reproductible with all twitch_api examples.

Code (and examples) uses twitch_api crates with "reqwest", "helix", "client", "twitch_oauth2", "eventsub", "hmac" features.

All building without error as long as the "reqwest" dependency is imported with a version lower than 0.12.* (and with twitch_oauth2 version lower than 0.13.* which depends on reqwest 0.12.* too)

Here is a example of code which generating error compilation (twitch_api examples are same way writring)

Cargo.toml :

twitch_api = { features = ["reqwest", "helix",  "client", "twitch_oauth2", "eventsub", "hmac"] }
twitch_types = { version = "0.4.4" }
twitch_oauth2 = { version = "0.13.0", features = ["reqwest", "client"] }
reqwest = { version = "0.12.2" }

Lib.rs :

let client: HelixClient<reqwest::Client> = HelixClient::default();            // <--- ERROR IS HERE ON HelixClient when instanciating. Test and same 
 error with default(), new() or with_client(). Same with TwitchClient too.
let twitch_auth_token = self::get_twitch_auth_secret(secrets_manager, "twitch_auth_user_token", &client);
    match twitch_user_token.await {
        Ok(r_ok) => {
            log::info!("get_twitch_auth_secret() > OK = {:#?}", r_ok);
            return Ok(r_ok)
        },
        Err(r_error) => {
 [...]

Generating error is :

error[E0277]: the trait bound `reqwest::Client: twitch_api::HttpClient` is not satisfied
  --> twitch_access_token_manager\twitch_oauth_connection.rs:94:48
   |
94 |     let client: HelixClient<reqwest::Client> = HelixClient::default();
   |                                                ^^^^^^^^^^^ the trait `twitch_api::HttpClient` is not implemented for `reqwest::Client`, which is required by `twitch_api::HelixClient<'_, _>: std::default::Default`
   |
   = help: the following other types implement trait `twitch_api::HttpClient`:
             std::boxed::Box<C>
             twitch_api::twitch_oauth2::client::DummyClient
             reqwest::async_impl::client::Client
             std::sync::Arc<C>
             twitch_api::DummyHttpClient
   = note: required for `twitch_api::HelixClient<'_, reqwest::Client>` to implement `std::default::Default`

I have tried to check reqwest changelog of 0.12.* in order to underestand and maybe fix it but I doesn't find difference that explain this bug.

Perhaps I missed the modified code explaining this error, or even perhaps I misunderstand how it works but I hope you can help me and if it is indeed a bug, correct it: )

I have read #401 and #404 issus but no solution for this error seem not to be fix my building error.

If I can help, it would be a pleasure, but I admit that right away, I'm completely confused about how to move forward with this problem.

Thanks all o/

I have read #401 and #404 issus but no solution for this error seem not to be fix my building error.

Can you try #404 as a git dependency?

[dependencies]
twitch_api = { git = "https://github.com/twitch-rs/twitch_api.git", branch = "deps/reqwest-http-and-stuff", features = ["..."] }

Seems like a duplicate of #401.

Can you try #404 as a git dependency?

Yes, I forgot to to mention that i have try #404 solution. So tireding day, sorry.

And that make another error in src/helix/client/client_ext.rs

error[E0277]: the trait bound `&twitch_types::basic::UserIdRef: IntoCow<'_, UserIdRef>` is not satisfied
   --> .cargo\git\checkouts\twitch_api-e5fea103d3f2733c\dd1fae3\src\helix\client\client_ext.rs:333:70
    |
333 |         let req = helix::streams::GetFollowedStreamsRequest::user_id(user_id);
    |                   -------------------------------------------------- ^^^^^^^ the trait `IntoCow<'_, UserIdRef>` is not implemented for `&twitch_types::basic::UserIdRef`
    |                   |
    |                   required by a bound introduced by this call
    |
    = help: the following other types implement trait `IntoCow<'a, Ref>`:
              <UserId as IntoCow<'a, UserIdRef>>
              <DisplayName as IntoCow<'a, DisplayNameRef>>
              <std::borrow::Cow<'a, S> as IntoCow<'a, R>>
              <Nickname as IntoCow<'a, NicknameRef>>
              <MsgId as IntoCow<'a, MsgIdRef>>
              <HexColor as IntoCow<'a, HexColorRef>>
              <BadgeSetId as IntoCow<'a, BadgeSetIdRef>>
              <ChatBadgeId as IntoCow<'a, ChatBadgeIdRef>>
            and 89 others
rustc[E0277](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B0%5D?0#file%3A.cargo%2Fgit%2Fcheckouts%2Ftwitch_api-e5fea103d3f2733c%2Fdd1fae3%2Fsrc%2Fhelix%2Fclient%2Fclient_ext.rs)
client_ext.rs(333, 19): required by a bound introduced by this call
get_followed_streams.rs(71, 34): required by a bound in `GetFollowedStreamsRequest::<'a>::user_id`

and

error[E0277]: the trait bound `&twitch_types::basic::UserIdRef: IntoCow<'_, UserIdRef>` is not satisfied
   --> .cargo\git\checkouts\twitch_api-e5fea103d3f2733c\dd1fae3\src\helix\client\client_ext.rs:377:92
    |
377 |         let req = helix::subscriptions::GetBroadcasterSubscriptionsRequest::broadcaster_id(user_id);
    |                   ------------------------------------------------------------------------ ^^^^^^^ the trait `IntoCow<'_, UserIdRef>` is not implemented for `&twitch_types::basic::UserIdRef`
    |                   |
    |                   required by a bound introduced by this call
    |
    = help: the following other types implement trait `IntoCow<'a, Ref>`:
              <UserId as IntoCow<'a, UserIdRef>>
              <DisplayName as IntoCow<'a, DisplayNameRef>>
              <std::borrow::Cow<'a, S> as IntoCow<'a, R>>
              <Nickname as IntoCow<'a, NicknameRef>>
              <MsgId as IntoCow<'a, MsgIdRef>>
              <HexColor as IntoCow<'a, HexColorRef>>
              <BadgeSetId as IntoCow<'a, BadgeSetIdRef>>
              <ChatBadgeId as IntoCow<'a, ChatBadgeIdRef>>
            and 89 others
rustc[E0277](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B2%5D?2#file%3A.cargo%2Fgit%2Fcheckouts%2Ftwitch_api-e5fea103d3f2733c%2Fdd1fae3%2Fsrc%2Fhelix%2Fclient%2Fclient_ext.rs)
client_ext.rs(377, 19): required by a bound introduced by this call
get_broadcaster_subscriptions.rs(70, 48): required by a bound in `GetBroadcasterSubscriptionsRequest::<'a>::broadcaster_id`

I don't have enough rust skills to dissect all that I think, that's why I'm asking for help and reporting this error in order to check if this is indeed a bug between versions or if it just comes from me, this uqi is possible ^^

Oh my bad, you need to add the following if you take twitch_api as a git dependency (see #256):

[dependencies]
twitch_api = { git = "https://github.com/twitch-rs/twitch_api.git", branch = "deps/reqwest-http-and-stuff", features = ["..."] }

[patch.crates-io.twitch_types]
git = "https://github.com/twitch-rs/twitch_api.git"
branch = "deps/reqwest-http-and-stuff" # pretty sure you need that too

Ho yes, I forgot to add the patch even though I should have added it before (#256 ) ^^

So, the patch fix previous UserIdRef error but there is always error like first :

error[E0277]: the trait bound `twitch_api::TwitchClient<'_, reqwest::Client>: twitch_oauth2::client::Client` is not satisfied
   --> twitch_access_token_manager\twitch_oauth_connection.rs:103:101
    |
103 |     let twitch_user_token = self::get_twitch_auth_secret(secrets_manager, "twitch_auth_user_token", &client);
    |                             ----------------------------                                            ^^^^^^^ the trait `twitch_oauth2::client::Client` is not implemented for `twitch_api::TwitchClient<'_, reqwest::Client>`
    |                             |
    |                             required by a bound introduced by this call
    |
    = help: the following other types implement trait `twitch_oauth2::client::Client`:
              twitch_oauth2::client::DummyClient
              reqwest::Client
rustc[E0277](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B3%5D?3#file%3Atwitch_access_token_manager%2Ftwitch_oauth_connection.rs)
twitch_oauth_connection.rs(103, 29): required by a bound introduced by this call
twitch_oauth_connection.rs(686, 14): required by a bound in `twitch_access_token_manager::twitch_oauth_connection::get_twitch_auth_secret`

you need to also patch twitch_oauth2 to be the git branch

#404 is merged now, so Cargo.toml should be

[dependencies]
twitch_api = { git = "https://github.com/twitch-rs/twitch_api/" }
twitch_oauth2 = { git = "https://github.com/twitch-rs/twitch_api/" }
twitch_types = { git = "https://github.com/twitch-rs/twitch_api/" }

# workaround for https://github.com/twitch-rs/twitch_api/issues/256
[patch.crates-io.twitch_types]
git = "https://github.com/twitch-rs/twitch_api"
[patch.crates-io.twitch_oauth2]
git = "https://github.com/twitch-rs/twitch_api"

note, you may have to do cargo update -p twitch_api -p twitch_types -p twitch_oauth2

Does it work now @Nakuromi ?

Hi,

Sorry, I was in hospital yesterday but I'm could try it this afternoon and it's working !
Thanks very much 😊

I have to read more about cargo feature patch with git because I don't understand why it have to do have to add git submodul patch in this case though the git source is already added and no branch, rev or other specification is needed ^^

Thank's of merging the fix, all are working well :)