.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.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.