On this page
Function std::iter::from_coroutine
pub fn from_coroutine<G>(coroutine: G) -> FromCoroutine<G>
where
G: Coroutine<Return = ()> + Unpin,
🔬This is a nightly-only experimental API. (
iter_from_coroutine
#43122)
Creates a new iterator where each iteration calls the provided coroutine.
Similar to iter::from_fn
.
Examples
#![cfg_attr(bootstrap, feature(generators))]
#![cfg_attr(not(bootstrap), feature(coroutines))]
#![feature(iter_from_coroutine)]
let it = std::iter::from_coroutine(|| {
yield 1;
yield 2;
yield 3;
});
let v: Vec<_> = it.collect();
assert_eq!(v, [1, 2, 3]);
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/iter/fn.from_coroutine.html