"Streaming" generators?


#1

Will generators be able to return parts of their own state? For example, could something like the following ever work?

#![feature(generators)]

fn main() {
    let gen = || {
        let test = vec![1, 2, 3];
        yield &test[0..2];
    };
}

Absolutely useless playground link.


#2

The Iterator trait guarantees it will never be able to do this, because let a = iter.next(); let b = iter().next(); use_both(a,b) is supported.


#3

Generic Associated Types will enable an Iterator-like trait that allows this behavior. Getting generators to support it will probably involve all the same work required to allow internal borrows across suspension points, i.e. self-referential types.


#4

Whoops, duplicate.