Function std::iter::from_generator
source · [−]pub fn from_generator<G>(
generator: G
) -> impl Iterator<Item = <G as Generator<()>>::Yield> where
G: Generator<(), Return = ()> + Unpin,
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