#Immediately awaited future factory requires lifetime references to be static, can that be reduced?

4 messages · Page 1 of 1 (latest)

neon pelican
#

I am generating and .awaiting a ton of futures, like so:

iter((l..r).map(|x| {
        let foo = foo.clone();
        let bar = bar.clone();
        let baz = baz.clone();
        async move {
            // do something with foo, bar and baz
        })
    }))
    .buffered(CONCURRENT_REQS)
    .collect::<Vec<_>>()
    .await

The reason I need to clone everything before sending them into an async block is Rust doesn't know the async block will need to be awaited immediately, so it defaults to asking for static.

I am wondering if there's some idiom to let Rust know or an helper function from some library.


P.S.
In this case, we can declutter by writing a clone macro and doing clone!(foo, bar, baz, async_fn) but de-cluttering is not the issue here, I am rather looking into removing the need for the clones altogether.

sonic sequoia
#

dawg i'll be honest

#

i have no idea what you even said

small flicker