Questions tagged [rust-futures]

69 questions
2
votes
1 answer

How can I create interoperability between different Future traits in Rust?

I am trying to use the binance_async library, tokio, and futures to make concurrent orders to Binance. (See notes at the end of this question.) The binance_async functions I'm using return a binance_async::error::Result
leila-m
  • 97
  • 1
  • 9
1
vote
1 answer

Why does the async function in rust lib not generate a poll function

When I define an async function in main.rs, the async function generates a poll function and a context initialization function, like this: pub async fn hello_world() { println!("hello world!!!"); } #[tokio::main] async fn main() { …
super_jh
  • 21
  • 3
1
vote
1 answer

Could not prove that closure is Send

I want to process a vec of items concurrently. Basically, each item involves doing some I/O, but they are not dependant on one another. I could use futures::join_all (or in my case futures::try_join_all) to achieve that. Since I don't care about…
Link0
  • 655
  • 5
  • 17
1
vote
1 answer

tokio-tungstenite with tokio::select! macro?

The documentation for the tokio-tungstenite crate mostly just directs you to the examples section. The client example hasn't been updated in a few years and I saw some unfamiliar async code here and because Rust's async APIs are still in flux I…
Sergio Gliesh
  • 329
  • 1
  • 2
  • 8
1
vote
0 answers

Wrap a hyper::Body in a BufReader in Rust

I have a hyper::Body and I want to wrap it in a BufReader (for example tokio::io::BufReader, but futures_util::io::BufReader or any other is fine too). Using it directly didn't work: fn foo(body: hyper::Body) { let bufreader =…
kpcyrd
  • 11
  • 2
1
vote
1 answer

Rust - Using map with mutable reference and async; possibly using Stream?

Is there a way with Rust to perform the following operation without making models mutable? Possibly by using Stream? The core issue with using uuids.iter().map(...) appears to be (a) passing/moving &mut conn into the closure and (b) the fact that…
Awesome-o
  • 2,002
  • 1
  • 26
  • 38
1
vote
2 answers

Does the Future trait implementation "force" you to break noalias in rust?

I'llI was thinking about the rust async infrastructure and at the heart of the API lies the Future trait which is: pub trait Future { type Output; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; } According to…
fakedrake
  • 6,528
  • 8
  • 41
  • 64
1
vote
2 answers

How to get the result of the first future to complete in a collection of futures?

I have a bunch of async_std::UdpSocket and want to drive them all until the first one completes, then get the result from its corresponding u8 buffer. I've tried // build sockets and buffers let sockets = Vec::new(); let buffers =…
Ben Little
  • 57
  • 5
1
vote
1 answer

Appending to a vector inside a buffered future - Rust

The following code fails with cannot move out of `my_number_vector`, a captured variable in an `FnMut` closure move out of `my_number_vector` [dependencies] futures = "0.3.21" tokio = "1.19.2" use futures::{stream,…
Corfucinas
  • 353
  • 2
  • 11
1
vote
2 answers

Best practice to avoid writing duplicate code for sync traits and their async counterpart

I stumbled upon this issue while writing a small custom protocol that extends both the std::io::Write and futures::io::AsyncWrite (as well as the Read traits). I noticed writing a lot of duplicate code, as the protocol behaves exactly the same…
Plebshot
  • 210
  • 1
  • 9
1
vote
1 answer

Async unbuffered channel that blocks on read and on write

For threaded applications, the Rust standard library provides std::sync::mpsc::sync_channel, a buffered channel which blocks on the reading end when the buffer is empty and blocks on the writing end when the buffer is full. In particular, if you set…
A. Kriegman
  • 510
  • 1
  • 4
  • 18
1
vote
1 answer

Rust Async Executor Memory Ordering Guarantees When Moving Tasks Across Threads?

This is a rather basic question regarding the memory ordering guarantees inside the Rust async ecosystems. However, I don't seem to find a clear answer anywhere. C++ memory ordering specifies the memory ordering from a thread-based…
First_Strike
  • 1,029
  • 1
  • 10
  • 27
1
vote
2 answers

Chaining adapters with custom `futures::Stream` breaks trait bounds

I needed to implement a custom Stream that yields items in a sliding window (ie. [1, 2, 3] => [(1, 2), (2, 3)]). So I implemented and gave it an adapter called .tuple_windows(). Allowing the following code let iter =…
Midnight Exigent
  • 615
  • 4
  • 15
1
vote
2 answers

Is there a tuple_windows() adapter for async streams?

I have a code the looks like this use itertools::Itertools; let (tx, rx) = std::sync::mpsc::channel(); tokio::spawn(async move { for (v1, v2) in rx.into_iter().tuple_windows() { // do some computation } } for v in (0..) { …
Midnight Exigent
  • 615
  • 4
  • 15
1
vote
1 answer

How can I wrap a dynamically typed stream for API convenience?

I'm looking to implement a wrapper struct for any stream that returns a certain type, to cut down on the dynamic keywords littering my application. I've come across BoxStream, but have no idea how to make use of it in Stream::poll_next. Here's what…
eltiare
  • 1,817
  • 1
  • 20
  • 28