.map_async(...).collect::<Vec<_>>()

One thing I like to do in traditional Rust is:

let ans: Vec<_> = collection.iter().map(...).collect::<Vec<_>>()

Now, I'm wondering if there is an easy way to do:

let ans: Vec<_> = collection.iter().map_async(...).collect::<Vec<_>>().await;

the behavior is that it starts all the async blocks, awaits them all, and upon completion, collects them into a Vec<_> .

1 Like

The StreamExt::then combinator does this.