Function core::iter::from_generator

source ·
pub fn from_generator<G: Generator<Return = ()> + Unpin>(
    generator: G
) -> FromGenerator<G>
🔬This is a nightly-only experimental API. (iter_from_generator #43122)
Expand description

Creates a new iterator where each iteration calls the provided generator.

Similar to iter::from_fn.

Examples

#![feature(generators)]
#![feature(iter_from_generator)]

let it = std::iter::from_generator(|| {
    yield 1;
    yield 2;
    yield 3;
});
let v: Vec<_> = it.collect();
assert_eq!(v, [1, 2, 3]);
Run
This documentation is an old archive. Please see https://rust.docs.kernel.org instead.