rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.4k stars 626 forks source link

Async transformations on arrays #2672

Open segeljakt opened 1 year ago

segeljakt commented 1 year ago

Would it be possible to support async transformations on arrays?

async fn map_async<const N: usize, A, B, Fut>(
    array: [A;N],
    fun: Fn(A) -> Fut
) -> [B;N]
    where Fut: Future<Output = B>;

I ran into a case where I'd like to allocate an array of TCP connections.

let sockets = map_async(["127.0.0.1:8000", "127.0.0.1:8001"], connect_socket);

Currently I need to write this in the form of a macro.

let sockets = map_async!(["127.0.0.1:8000", "127.0.0.1:8001"], connect_socket);