-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-coroutinesArea: CoroutinesArea: CoroutinesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`GATs-triagedIssues using the `generic_associated_types` feature that have been triagedIssues using the `generic_associated_types` feature that have been triagedT-langRelevant to the language teamRelevant to the language team
Description
Since #67160 has been merged in December, having a GAT with lifetimes should be possible (See the StreamingIterator
example in that PR).
The current trait-defition of a coroutine is the following:
pub trait Coroutine<R = ()> {
type Yield;
type Return;
fn resume(
self: Pin<&mut Self>,
arg: R
) -> CoroutineState<Self::Yield, Self::Return>;
}
The issue here is that the Yield
can't be parameterized with a lifetime, so yielding a reference from a coroutine is not possible in its current state.
By using a GAT for the Yield
AT, it would be possible to return a local reference.
I also don't see why the resume argument type could not have been expressed with a GAT, so at the end we would use the following trait definition for a coroutine:
pub trait Coroutine {
type Resume<'a>;
type Yield<'a>;
type Return;
fn resume<'a, 'b>(
self: Pin<&'a mut Self>,
arg: Self::Resume<'b>
) -> CoroutineState<Self::Yield<'a>, Self::Return>;
}
Patryk27, luojia65, EFanZh, tema3210, petrosagg and 10 more
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-coroutinesArea: CoroutinesArea: CoroutinesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`GATs-triagedIssues using the `generic_associated_types` feature that have been triagedIssues using the `generic_associated_types` feature that have been triagedT-langRelevant to the language teamRelevant to the language team