twitch-rs / twitch_api

Rust library for talking with the Twitch API aka. "Helix", TMI and more! Use Twitch endpoints fearlessly!
Apache License 2.0
151 stars 33 forks source link

wierd interaction due to two `twitch_types` crates used #256

Open Emilgardis opened 2 years ago

Emilgardis commented 2 years ago

Due to how we currently have twitch_types used in twitch_api2 and twitch_oauth2, there's a wierd interaction happening due to the two twitch_api crates used are not the same due to pathing.

To circumvent the issue, users that have specified twitch_api2 as a path or git dependency will need to do the following:

[dependencies]
twitch_api = { 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"

this issue manifests as

error[E0277]: the trait bound `&twitch_types::basic::UserIdRef: IntoCow<'_, UserIdRef>` is not satisfied
   --> /Users/emil/.cargo/git/checkouts/twitch_api-e5fea103d3f2733c/e9ed7c5/src/helix/client/client_ext.rs:302:70
    |
302 |         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>`:
              <&'a BadgeSetId as IntoCow<'a, BadgeSetIdRef>>
              <&'a BadgeSetIdRef as IntoCow<'a, BadgeSetIdRef>>
              <&'a BlockedTermId as IntoCow<'a, BlockedTermIdRef>>
              <&'a BlockedTermIdRef as IntoCow<'a, BlockedTermIdRef>>
              <&'a CategoryId as IntoCow<'a, CategoryIdRef>>
              <&'a CategoryIdRef as IntoCow<'a, CategoryIdRef>>
              <&'a CharityCampaignId as IntoCow<'a, CharityCampaignIdRef>>
              <&'a CharityCampaignIdRef as IntoCow<'a, CharityCampaignIdRef>>
            and 83 others
note: required by a bound in `GetFollowedStreamsRequest::<'a>::user_id`
   --> /Users/emil/.cargo/git/checkouts/twitch_api-e5fea103d3f2733c/e9ed7c5/src/helix/endpoints/streams/get_followed_streams.rs:70:34
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `GetFollowedStreamsRequest::<'a>::user_id`

error[E0277]: the trait bound `&twitch_types::basic::UserIdRef: IntoCow<'_, UserIdRef>` is not satisfied
   --> /Users/emil/.cargo/git/checkouts/twitch_api-e5fea103d3f2733c/e9ed7c5/src/helix/client/client_ext.rs:343:92
    |
343 |         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>`:
              <&'a BadgeSetId as IntoCow<'a, BadgeSetIdRef>>
              <&'a BadgeSetIdRef as IntoCow<'a, BadgeSetIdRef>>
              <&'a BlockedTermId as IntoCow<'a, BlockedTermIdRef>>
              <&'a BlockedTermIdRef as IntoCow<'a, BlockedTermIdRef>>
              <&'a CategoryId as IntoCow<'a, CategoryIdRef>>
              <&'a CategoryIdRef as IntoCow<'a, CategoryIdRef>>
              <&'a CharityCampaignId as IntoCow<'a, CharityCampaignIdRef>>
              <&'a CharityCampaignIdRef as IntoCow<'a, CharityCampaignIdRef>>
            and 83 others
note: required by a bound in `GetBroadcasterSubscriptionsRequest::<'a>::broadcaster_id`
   --> /Users/emil/.cargo/git/checkouts/twitch_api-e5fea103d3f2733c/e9ed7c5/src/helix/endpoints/subscriptions/get_broadcaster_subscriptions.rs:69:48
    |
69  |     pub fn broadcaster_id(broadcaster_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
    |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `GetBroadcasterSubscriptionsRequest::<'a>::broadcaster_id`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `twitch_api` due to 2 previous errors

Can this be solved neatly without requiring a patch?

Nerixyz commented 2 years ago

For future visitors, after the move from twitch_api2 to twitch-rs/twitch_api:

[dependencies]
# rev isn't required, but it's good to pin a specific revision
twitch_api = { git = "https://github.com/twitch-rs/twitch_api.git", rev = "340a582" }

# workaround for https://github.com/twitch-rs/twitch_api/issues/256
[patch.crates-io.twitch_types]
git = "https://github.com/twitch-rs/twitch_api.git"
rev = "340a582" # only if you pinned the repo to a specific revision

If you don't want to rename every import of twitch_api2 to twitch_api, add the following line in your main.rs / lib.rs:

extern crate twitch_api as twitch_api2;
Emilgardis commented 2 years ago

It's also possible to do

[dependencies]
twitch_api2 = {package = "twitch_api", ...}
Nerixyz commented 2 years ago

Oh didn't know that. It's much better than extern crate.

Nerixyz commented 8 months ago

Can this be solved neatly without requiring a patch?

Just ran into this again. Maybe this should be a monorepo instead of using submodules? I'm not sure how releasing works then, however.

Emilgardis commented 8 months ago

I don't think monorepo solves it, since the source for the twitch_types would still be crates-io when twitch_api is included as a git source.

eframe/egui has the same problem, see https://github.com/emilk/eframe_template/blob/02ee968537e783e375a0e439426518bf91e762b6/Cargo.toml#L41-L43