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
0 answers

How to write a Rust generator that returns an async_std stream?

Let's say I have a trait IMyWriter that has a function flush_to_disk that gets an iterator of the pieces to write. Each piece that's written should yield a Result object. use async_trait::async_trait; use…
Vitali
  • 3,411
  • 2
  • 24
  • 25
1
vote
0 answers

Cannot borrow TlsStream in RefCell as mutable

I have a struct containing a RefCell wrapping a TlsStream. I tested replacing the TlsStream with an i32 and am able to mutate the struct member, but the compiler errors when using the stream. I get the following error when attempting…
Josh Abraham
  • 959
  • 1
  • 8
  • 18
0
votes
0 answers

Rust async thread number and task stream flexibility

I’ve been trying to develop a program that runs asynchronous tasks concurrently using Rust and the async-std crate. Because of the environment this program will run in, it strictly needs only 2 threads, both of which will make use of asynchronous…
0
votes
1 answer

async-std::net:TcpStream read function does not return although data is available

Hi I have a strange bug that I am debugging for a few days now. I am using async-std::net::TcpStream as part of a larger program like this: // init socket and connection let socket = std::net::SocketAddrV4::new(addr, port); let stream =…
musli
  • 11
  • 2
0
votes
0 answers

Can't use sqlx Executor as a trait object

I need to use the Executor type as a trait object but I get the following error: the trait `Executor` cannot be made into an object. the trait cannot be made into an object because it requires `Self: Sized` If we look into the trait definition, we…
JasterV
  • 17
  • 5
0
votes
2 answers

Is there any performance advantage to use async/await amid synchronous code?

Im trying to understand when to use async and when it can improve performance. I know it’s most-powerful in replacing otherwise-blocking IO operations like file IO, http calls, database operations, etc., but I was wondering if there’s any point…
Jam
  • 476
  • 3
  • 9
0
votes
0 answers

Async middleware, get async result before calling next middleware

I'm trying to create a middleware with redis and actix-web. This is what I want for my middleware: -> Concat the request path and query_string, to create a redis key. -> Get the value stored within redis db. -> If not null, return this content. ->…
Victor D
  • 15
  • 6
0
votes
0 answers

Single threaded asynchronous event loop with `winit`

I'm trying to build an NES emulator using winit, which entails building a game loop which should run exactly 60 times per second. At first, I used std::thread to create a separate thread where the game loop would run and wait 16 milliseconds before…
0
votes
1 answer

How to compose multiple async operation when using join_all in Rust

I have multiple async operations that are in stages. For example, let's say the first stage of async operations is making multiple requests, the second stage is parsing the results of the multiple http requests to JSON. When using join_all, I can…
Finlay Weber
  • 2,989
  • 3
  • 17
  • 37
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…
0
votes
2 answers

Easiest way to loop until async function returns in Rust

I'm writing a program to play Chess. My Game class has the async function play. This function returns when the game ends, returning a Winner enum, which is either a stalemate or a win for some colour. In my main fn, I want to run game.play, then run…
0
votes
1 answer

Creating an asynchronous task from a method, from within a method of the same structure

How can one method of a structure run another method of the same structure as a task? Forgive me for possible stupidity, I'm new to Rust. The compiler complains that self cannot survive the body of the function in which it is called. But isn't this…
KusochekDobra
  • 23
  • 1
  • 3
0
votes
1 answer

Is it okay to store global clients vector with unsafe when implementing a chat server with async_std?

I have implemented a chat server which stores the connected users and if a user send a message, the server echoes it to all other clients. I have C++ background so I made a global static mut USERS:Vec variable to store and access the…
eminfedar
  • 558
  • 3
  • 16
0
votes
0 answers

Store references to `async` functions

I want to store pointers to async functions in some static list and call them later. How can I do this? E.g. //async fn foo() { } //async fn bar() { } type MyFn = fn(); const RUNNERS: &[MyFn] = &[ foo, bar, ]; async fn run() { …
ensc
  • 6,704
  • 14
  • 22
0
votes
0 answers

Rust - How to use a synchronous and an asynchronous crate in one application

I began writing a program using the Druid crate and Crabler crate to make a webscraping application whose data I can explore. I only realized that merging synchronous and asynchronous programming was a bad idea long after I had spent a while…