Firstly, thanks for this (pre) RFC, it looks really promising 
Wrt. the Iterator adapter wouldn’t following be better, or did I miss some thing?
impl<G,T> Iterator for G where G: FnMut() -> CoResult<T,()> {
type Item = T;
fn next(&mut self) -> Option<T> {
match self.call() {
Yield(x) => Some(x),
Return(*) => None
}
}
}
Lastly I wonder restrictions of borrows across yields might sometimes be a bit surprising (through needed) if e.g. the borrow is to some value on the heap guarded by a hoisted struct or e.g.:
//in coro
|outer| {
for inner in outer.iter() {
// isn't now the OuterIter on the stack (=> hoisted) and
// and inner has a borrow to it
for element in inner.iter() {
// now inner and InnerIter live over a yield, which they are
//not allowed to because they have a borrow to the hoisted OuterIter?!
yield element;
}
}
}
I probably misunderstood/overlooked something, but if not wouldn’t this be kind of a problem (Coros would still be helpfull, but a bit less and they also would be more confusing)?
EDIT: is just noticed there is an error |outer| would be a parameter returned from yield, so correct would be if outer is brought into the scope of the corotine by closing over it.
Correction:
type ElCoro = FnMut() -> CoResult<El, ()>;
fn random_fn<'a>(outer: &'a Some2DCollectionOfEl) -> impl ElCoror + 'a {
|| {
for inner in outer.iter() {
// ...
for element in inner.iter() {
// ...
yield element;
}
}
}
}