Function core::iter::from_generator
source · pub fn from_generator<G: Generator<Return = ()> + Unpin>(
generator: G
) -> impl Iterator<Item = G::Yield>
🔬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