trait Generator as in nightly:
trait Generator {
type Yield;
type Return;
fn resume(
self: Pin<&mut Self>
) -> GeneratorState<Yield, Return>;
}
There has been discussion of somehow providing resume arguments for generators, which could be useful for e.g. providing a future’s Waker without TLS.
A theoretical FnPin:
trait FnPin<Args> {
type Output;
extern "rust-call" fn call_pin(
self: Pin<&mut Self>,
args: Args
) -> Output;
}
If all we care about is generators as used by the compiler to implement futures, it doesn’t really matter what backs it up.
It feels to me like FnPin is more “pure”, though, as it can be used for any !Unpin-requiring FnMut-style computation, not just that which has the Yield/Return/implementation-defined-on-exhausted semantics. Generator is then just a FnPin<Output=GeneratorResult<Yield, Return>>.
Of course, this can’t join the existing Fn hierarchy, as a pinned reference is incompatible with FnMut and FnOnce "calling convention"s, and Fn implies the other two.
This is mostly just rambling. I’m not sure which is really the better option, if there even is one. I suspect for proper language integration, even if we have FnPin for the general case, we’ll want Generator: FnPin as a “specialization”.
.)