Questions tagged [rust-futures]

69 questions
0
votes
1 answer

How to store a pointer to an async method in a container?

I have a struct that defines multiple async methods, and I'd like to store a pointer of each of them in a HashMap, so that I can call any method in one single line, knowing only a key that is given in parameter. The aim here is to avoid as much as…
0
votes
1 answer

Rust - return a future in a closure

I am trying to add a return type of a future in a closure. But the compiler is telling me that `impl Trait` only allowed in function and inherent method return types, not in closure return I have have also tried wrapping it in Box but that didn't…
Sanskar Jethi
  • 544
  • 5
  • 17
0
votes
1 answer

Can we pass associated values going with futures to the next step so that we can map the original param with the future result?

By using join_all we can execute a batch of futures simultaneously and get the results at once, but sometime we need to map the original parameter with its result, how can we achieve that? Like the code below, I want to know which result associates…
Suge
  • 2,808
  • 3
  • 48
  • 79
0
votes
1 answer

Rust needs static lifetime when waiting on the same future?

I am trying to get the OAuth token from the server, so I made a struct named Token. In order to keep only one request when the token is expired, I keep a reference for the requesting future, let other requests keep waiting for it returns.…
Henry
  • 531
  • 3
  • 12
0
votes
1 answer

Manual Futures and aysnc move: Type doesn't live long enough even though I'm cloning it

I've got this function that is doing some work with manually created futures. pub type Response = Pin> + Send>> pub fn get_list
phayes
  • 1,432
  • 1
  • 12
  • 11
0
votes
1 answer

Unpinning a BoxStream to send using Tonic gRPC stream

I am new to Rust and writing a simple application that will stream some values over gRPC, using Tonic. These values are initially acquired from an external library as a BoxStream (Pin>), and tonic's API requires something that implements…
0
votes
1 answer

Convert Stream, _>> to Stream>

Suppose I have a stream of Result: let v = Ok(vec![(), ()]); let s = stream::once(future::ready(v)); How can I make s be the return value of a function with return type impl Stream?
Kafji
  • 31
  • 5
0
votes
0 answers

Best nested parallelization approach with Rust Futures

Not sure if this is even a good question to ask but I hope that the answer could also cover if nested parallelization is bad or not in addition to my main questions. Thank you so much! Suppose I have tasks a, b, c and d. These tasks each have their…
Nicholas
  • 1,883
  • 21
  • 39
-2
votes
0 answers

What is the best practice to handle associated data with a future in FuturesUnordered?

I have a dynamic number of "streams" (it's actually a Quinn crate RecvStream that doesn't implement the Copy trait) and I call this code on it: let fut = stream.read(&mut buffer); streams.push(fut); The buffer is a simple &[u8] and the streams is…
Cthutu
  • 8,713
  • 7
  • 33
  • 49
1 2 3 4
5