Getting a Future from a Vector and a function I'm pretty new to Rust and to it's async/await model, and I'm trying to do something that looks like a specialized Haskell's traverse function. Given a Vec&lt;T&gt; and a function T -&gt; Future&lt;Output = R&gt; I want to get a Future&lt;Output = Vec&lt;R&gt;&gt;.

At the moment, I have the following:

use futures::{FutureExt, StreamExt};

pub async fn traverse&lt;I, T, R, F, FN&gt;(xs: I, f: FN) -&gt; Vec&lt;R&gt;
where
    I: IntoIterator&lt;Item = T&gt;,
    F: FutureExt&lt;Output = R&gt;,
    FN: Fn(T) -&gt; F,
{   
    futures::stream::iter(xs)
        .fold(vec![], |acc, item| {
            f(item).map(move |app| {
                let mut a = acc;
                a.push(app);

                a
            })
        })
        .await
}



It works as expected, but doesn't feel very idiomatic. Does anybody has suggestion how to improve this function?
I think the best is to simply use then() and collect():

use futures::{Future, StreamExt};

pub async fn traverse&lt;I, T, F, Fut, O&gt;(xs: I, f: F) -&gt; Vec&lt;O&gt;
where
    I: IntoIterator&lt;Item = T&gt;,
    F: Fn(T) -&gt; Fut,
    Fut: Future&lt;Output = O&gt;,
{
    futures::stream::iter(xs).then(f).collect().await
}


Note:


futures generic should be name Fut
function generic should be name F
I rename R as O but I don't know if it's better but it's my way.
Doesn't need FutureExt