Skip to content
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

wierd interaction due to two twitch_types crates used #256

Open
Emilgardis opened this issue May 19, 2022 · 5 comments
Open

wierd interaction due to two twitch_types crates used #256

Emilgardis opened this issue May 19, 2022 · 5 comments

Comments

@Emilgardis
Copy link
Member

Emilgardis commented May 19, 2022

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
Copy link
Contributor

Nerixyz commented Aug 15, 2022

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
Copy link
Member Author

Emilgardis commented Aug 15, 2022

It's also possible to do

[dependencies]
twitch_api2 = {package = "twitch_api", ...}

@Nerixyz
Copy link
Contributor

Nerixyz commented Aug 15, 2022

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

@Nerixyz
Copy link
Contributor

Nerixyz commented Feb 24, 2024

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants