[][src]Macro genawaiter::generator_mut

macro_rules! generator_mut {
    ($name:ident, $start:expr) => { ... };
}

Creates a generator on the stack.

This macro creates a generator with the name you pass in:

This example is not tested
generator_mut!(my_name, ...)
// Think of this as:
let my_name = generator_mut!(...)

The full type of the new variable is &mut Gen<'_, Y, R, impl Future>. Y is the type yielded from the generator. R is the type of the resume argument. Future::Output is the type returned upon completion of the generator.

The generator's state is stored on the stack of the current function. The state is pinned in place, so it cannot escape the scope of the function. However, since the generator is a reference, you can pass it around to other functions:

fn consume_generator(gen: &mut Gen<'_, i32, (), impl Future>) {
    gen.resume();
}

generator_mut!(gen, odd_numbers_less_than_ten);
consume_generator(gen);