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
创建一个新的迭代器,每次迭代都调用提供的生成器。
类似于 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