yoshuawuyts / futures-concurrency

Structured concurrency operations for async Rust
https://docs.rs/futures-concurrency
Apache License 2.0
400 stars 31 forks source link

Update traits to use AFITs / associated `impl Future` #162

Open yoshuawuyts opened 9 months ago

yoshuawuyts commented 9 months ago

Now that async traits are stable, we may want to consider filing a patch to use them. Not sure yet if we should merge it, but we should at least try it out.

For Join it should not be an AFIT, but instead use an impl Future as its associated type.

yoshuawuyts commented 9 months ago
// most traits like this
impl<A: Future, B: Future> Race for (A, B) {
    async fn race(self) -> (A::Output, B::Output) ;
}

// but `Join` should be like this...
impl<A: Future, B: Future> Join for (A, B) {
    type Future = impl Future<Output = (A::Output, B::Output)>;
    fn join(self) -> Self::Future;
}

// ... so that we can implement it in std like this
impl<A: Future, B: Future> IntoFuture for (A, B) {
    type IntoFuture = impl Future<Output = (A::Output, B::Output)>;
    fn into_future(self) -> Self:: IntoFuture;
}