Questions tagged [rust-async-std]

Async version of the Rust standard library.

async-std is a foundation of portable Rust software, a set of minimal and battle-tested shared abstractions for the broader Rust ecosystem. It offers std types, like Future and Stream, library-defined operations on language primitives, standard macros, I/O and multithreading, among many other things.

async-std is available from crates.io. Once included, async-std can be accessed in use statements through the path async_std, as in use async_std::future.

48 questions
1
vote
1 answer

AsyncRead for UdpSocket

I'm trying to implement AsyncRead for a UdpSocket that have an async recv function and I have some difficulties calling poll on my future: use async_std::{ io::Read as AsyncRead, net::UdpSocket, }; struct MyUdpWrapper { socket:…
Ervadac
  • 936
  • 3
  • 9
  • 26
1
vote
1 answer

How to await `JoinHandle`s and update `JoinHandle`s at the same time?

Is it possible to both read a stream of Futures from a set of JoinHandle<()> tasks and update that set of tasks with new tasks at the same time? I currently have a Service that runs some long tasks. Only thing is, I would actually like to (if…
ralston3
  • 31
  • 3
1
vote
0 answers

Why do I get "error[E0308]: mismatched types" when the function pointer types match exactly

I've got a scenario where I want to pass a function pointer (or closure) that takes a mutable reference to a struct, as a way of letting the caller initialize that struct for me. The (very simplified) code looks like this: use…
1
vote
1 answer

Rust Generic Function Attempt for Async Reads

My goal is to reduce the following read_stream_***() functions into a generic fuction that can be passed different streams. use async_std::net::TcpStream; use async_std::{ task }; use async_std::io::{ stdin, BufReader, Stdin }; use async_std:: {…
sfanjoy
  • 640
  • 6
  • 16
1
vote
1 answer

How to fix select_all returning only one result instead of multiple results

My code can be boiled down to the following: let client = reqwest::Client::new(); let endpoints = vec!['http://google.com', 'http://www.yahoo.com', 'http://example.com']; let futures: Vec<_> = endpoints.iter().map(|endpoint| { return…
Finlay Weber
  • 2,989
  • 3
  • 17
  • 37
1
vote
1 answer

Is the return type of the connect() function of the async-std crate a type of Future?

The document of the function connect() says it would return a Future. This method will create a new TCP socket and attempt to connect it to the addr provided. The returned future will be resolved once the stream has successfully connected, or it…
Tim
  • 99
  • 1
  • 5
1
vote
1 answer

Unable to wrap an AsyncBufRead inner object due to returning data owned by current function

I am trying to wrap a stream object with the goal of introducing some timeouts on it's read operations, and am starting with just the bare skeleton, but not even this compiles: use futures::io::{AsyncBufRead, AsyncRead}; use std::io; use…
André Cruz
  • 500
  • 1
  • 5
  • 15
1
vote
1 answer

Awaiting on static data

I am connecting to a database. Once the credentials are inserted, the connector gives me back a (client, connection) tuple. Afterwards, a procedural macro must access some "global location", retrieves the credentials from there and wires the data…
Alex Vergara
  • 1,766
  • 1
  • 10
  • 29
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
0 answers

How to lock on asynchronous file-writes with seperate locks per file in Rust?

I have an actix-based API, that operates entirely async. There is one endpoint, that writes a file with a user-given filename on the filesystem (I use async-std library for async fs-operations). My problem now is, that I run into race-conditions…
Piwo
  • 1,347
  • 1
  • 12
  • 19
1
vote
1 answer

how to store Futures from 2 different async functions with equal signatures in vector

how to store Futures from 2 different async functions with equal signatures in vector? i have 2 functions in different crates: crate 1: pub async fn resolve( client: &String, site: &String, id: &String, ) -> Result
USA LOVER
  • 145
  • 5
1
vote
1 answer

Why is the Send trait required inside my match block?

I think my question relates to Rust Issue 57017. The following code does not compile and produces error: future cannot be sent between threads safely due to future created by async block is not 'Send' originating in async fn execute_fail. On the…
Dan
  • 5,013
  • 5
  • 33
  • 59
1
vote
1 answer

How to implement streams from future functions

in order to understand how streams work I was trying to implement an infinite number generator that uses random.org. The first thing I did, was implementing a version where I would call an async function called get_number and it would fill a buffer…
Jayson Reis
  • 708
  • 5
  • 14
1
vote
1 answer

Rust Streaming Pipeline

I'm finding Rust streaming documentation to be convoluted and examples non-existent. Trying to create a code example will likely be more confusing than outlining a problem. Given a read stream that is being passed to a consuming function, I'd like…
webish
  • 701
  • 2
  • 9
  • 17
1
vote
1 answer

Rust: how to use async-std + TLS + HTTP Proxy(http tunnel)?

I purchased an http proxy(supported http tunnel), but have no rust example code, I try to use the crate surf, but not found the proxy way, I have to implement it by myself. following is my code: use async_std::task::block_on; use…
Anunaki
  • 763
  • 2
  • 8
  • 18