W3cubDocs

/Rust

Macro iter

pub macro iter($($t:tt)*) {
    ...
}
🔬This is a nightly-only experimental API. (iter_macro #142269)

Creates a new closure that returns an iterator where each iteration steps the given generator to the next yield statement.

Similar to iter::from_fn, but allows arbitrary control flow.

Examples

#![feature(iter_macro, coroutines)]

let it = std::iter::iter!{|| {
    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/macro.iter.html