[][src]Macro genawaiter::stack::let_gen_using

macro_rules! let_gen_using {
    ($ name : ident, $ producer : expr $ (,) ?) => { ... };
}

Creates a generator using a producer defined elsewhere.

The first argument is the name of the resulting variable.

This example is not tested
let_gen!(my_generator, { /* ... */ });
// Think of this as the spiritual equivalent of:
let mut my_generator = Gen::new(/* ... */);

The second line is the producer that will be used. It can be one of these two things:

  1. The result of [stack_producer!] or stack_producer_fn!

  2. A function with this type:

    This example is not tested
    async fn producer(co: Co<'_, Yield, Resume>) -> Completion { /* ... */ }
    // which is equivalent to:
    fn producer(co: Co<'_, Yield, Resume>) -> impl Future<Output = Completion> { /* ... */ }

This macro is a shortcut for creating both a generator and its backing state (called a Shelf). If you (or your IDE) dislike macros, you can also do the bookkeeping by hand by using Gen::new, though note that this requires you to trade away safety.

Examples

See the module-level docs for examples.