egg-mode-rs / egg-mode

a twitter api crate for rust
https://crates.io/crates/egg-mode
Mozilla Public License 2.0
371 stars 65 forks source link

Add missing Send bounds for CursorIter. #102

Closed hdevalence closed 4 years ago

hdevalence commented 4 years ago

This allows using the CursorIter in a Send future.

QuietMisdreavus commented 4 years ago

I'd like to add a changelog entry for this PR. Would you like to be credited?

hdevalence commented 4 years ago

This feels like a pretty minor change to me but I don't have any objection to being credited.

QuietMisdreavus commented 4 years ago

It feels like a notable enough change (an infrastructure type can be used in more places) that i would like to list it. Personal preference, i guess. :woman_shrugging:

abonander commented 3 years ago

@QuietMisdreavus I know it's a really small change for a minor version bump but would you consider publishing this? It can be worked around with tokio::task::LocalSet but it's a bit of a hassle.

Edit: nevermind, because LocalSet explicitly opts-out of Send as well... heck.

abonander commented 3 years ago

Addendum: there's still an issue, Sync needs to be added to the trait object as well if you're using .call() manually since it necessarily borrows &CursorIter<...> across an await point.

It looks pretty trivial to get rid of the trait object entirely though? Then it's not even a minor version bump as CursorIter will automatically be Send + Sync if T::Item is Send + Sync. I see though that FutureResponse is a bit more complex to deal with since it comes from an async fn.

It turns out Sync is not strictly necessary but you have to lift the .call() to an assignment before .awaiting on it, I guess since the reference is technically required to live for the whole statement otherwise:

let mut friends_cursor = egg_mode::user::friends_ids(...);

// won't compile if the encapsulating future is required to be `Send`
let friends_page = friends_cursor.call().await?;

// compiles
let friends_call = friends_cursor.call();
let friends_page = friends_call.await?;