Questions tagged [rust-futures]
69 questions
0
votes
1 answer
Future- - 'Item' and 'Error' associated types not found?
I am experimenting with Tokio, Reqwest and Actix-web and creating am API that connects to SendGrid to send simple emails.
I am stuck on an error:
error[E0220]: associated type `Item` not found for `std::future::Future`
--> src\main.rs:20:79
…

John Watson
- 13
- 3
0
votes
3 answers
Async: how to keep using the same future in a loop with select (no_std environment)?
I have two async functions: get_message and get_event. I'd like to perform an action whenever a message arrives or an event comes and do that forever in an infinite loop.
The simplified setup looks like this:
use futures::{future::select,…

ynoxinul
- 1
- 1
0
votes
3 answers
Implement Future trait based on future available inside the struct
I'm trying to create a DelayedValue future that resolves to a value after a certain time period has elapsed. To do this I simply wanted to wrap the Sleep future from tokio crate. But I get errors relating to Pin and no matter what I do I can't seem…

John Smith
- 179
- 4
0
votes
0 answers
How can I pass a reference as a parameter into an async function in Rust?
I would like something as follows. Where my async fn my_fn(arg: &str) takes a reference and does something with it. Note that my_fn must be async because my real code does async stuff. See the Playground for the example.
use futures::Future;
use…

Dan
- 5,013
- 5
- 33
- 59
0
votes
1 answer
How to accept either ownerhip or mutable reference for the same method
I am making a library in Rust around a TCP protocol. And I am also trying to make it async runtime independent.
I would like to make it accept ownership of an existing connection OR accept a mutable reference to it. I.e. I want to let the caller say…

boen_robot
- 1,450
- 12
- 24
0
votes
0 answers
reusing futures::stream::Stream and modifying state of each element
I have a futures::stream::Stream which produces elements in the form <(State, impl std::fmt::Binary)> (Binary is an arbitrary placeholder for a trait I want to use):
let peers = (0..10).map(move |peer| async move {
let delay =…

Kevin
- 3,096
- 2
- 8
- 37
0
votes
0 answers
Grouping rust stream items
Streams are often described as 'async iterators'. I am more used to C++ iterators which encourage you to keep the intermediate states of the iterators for re-use in algorithms. It can be difficult to see how you neatly achieve more complex iterator…

tamathews01
- 47
- 6
0
votes
0 answers
How can I perform multiple concurrent requests with reqwest using a shared client reference?
I am trying to perform multiple concurrent GET requests using the reqwest library, while using a shared reference to the Client object. The idea is this will be a long-lived client, and as suggested in the docs, I would like to take advantage of the…

Lukas S.
- 5,698
- 5
- 35
- 50
0
votes
0 answers
Is it possible to turn a rust RocksDB iterator into a `Send + 'static` stream?
I've got a small RPC network protocol I've written, and there's a server-streaming method (very similar to gRPC style server-streaming) called range. The client sends start and end keys, and the server streams the values back. I'm using the tower…

broughjt
- 73
- 4
0
votes
0 answers
Idiomatic way in async/await Rust to route an input to an existing Future or a new one based on a condition
In async/await, what's the most idiomatic/efficient way to take an input buffer and, for each item, route it to an existing Future or a new one based on a condition? For example, you're running a server and each incoming packet might either be the…

John Stanford
- 993
- 1
- 7
- 18
0
votes
1 answer
Rust: future factory method results in compiler error: value requires that `'1` must outlive `'2`
I want to repeat a certain user-provided function multiple times in an async context. Thus, I thought about a non-async closure that produces futures which can be consumed/awaited.
A minimal reproducible example is the following:
let counter =…

phip1611
- 5,460
- 4
- 30
- 57
0
votes
1 answer
How to store a future without boxing it
I want to do the following
struct Stored> {
f: Option,
}
impl> Stored {
fn store(&mut self, f: F) {
let f = async {};
self.f = Some(f);
}
}
But it gives me the…

Gabriel Machado
- 401
- 3
- 14
0
votes
1 answer
How `tokio::spawn` handles the situation when the future can't be moved?
The function tokio::spawn is defined as follows:
pub fn spawn(future: T) -> JoinHandle
The future does not implement Copy trait, so it is moved into the function. But some futures can't be moved because it has pointers pointing to…

spockwang
- 897
- 1
- 6
- 15
0
votes
2 answers
Rust lifetimes in async wrapper for sync code
I am trying to create a Stream using a camera with a blocking capture method. The blocking call is wrapped with blocking::unblock.
use futures::stream;
use rscam::{Camera, Config};
fn frame_stream() -> impl stream::Stream {
let mut camera =…

Stonks3141
- 3
- 3
0
votes
1 answer
Rust futures -- use Box::pin or pin_mut outside futures::select
I had read the usage of futures::select, but I encounter an obstacle. here is my confusion: At the part of expression in select!, we should use a type implementing Unpin and FusedFuture, but here Pin on a Unpin is no effect accoring to usage of…

sunboy_zgz
- 11
- 4