iter in std::iter - Rust
Description: Creates a new closure that returns an iterator where each iteration steps the given generator to the next `yield` statement.

## iter

# Macro iter

Source

    pub macro iter($($t:tt)*) {
        ...
    }

🔬This is a nightly-only experimental API. (`iter_macro` #142269)
Expand description

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]);