Questions tagged [rust-tokio]

Tokio is an event-driven, non-blocking I/O platform for writing asynchronous applications with the Rust programming language.

Tokio aims to be:

  • Fast: Tokio's zero-cost abstractions give you bare-metal performance.

  • Productive: Tokio makes it easy to implement protocols and program asynchronously.

  • Reliable: Tokio leverages Rust's ownership and concurrency model to ensure thread safety.

  • Scalable: Tokio has a minimal footprint, and handles backpressure and cancellation naturally.

At a high level, it provides a few major components:

  • A multithreaded, work-stealing based task scheduler.
  • A reactor backed by the operating system's event queue (epoll, kqueue, IOCP, etc...).
  • Asynchronous TCP and UDP sockets.

You can find more information in

1053 questions
0
votes
1 answer

How do I create a tokio specialized transport to override the default tick implementation?

I'm attempting to write a streaming, pipelined server with a non-default tick() method in the transport. I thought this would do it: use std::io; use mio::net::TcpListener; use tokio_core::reactor::PollEvented; use tokio_io::{AsyncRead,…
SpamapS
  • 1,087
  • 9
  • 15
-1
votes
1 answer

How to make a tokio stream works concurrently

I would like to run a sequence of streams with several processes of the stream running concurrently. The test code that I tried is the following: use tokio; use tokio_stream::{self as stream, StreamExt}; use…
-1
votes
1 answer

Comparing handles vs streams for async operations in rust

In rust, we can write a vector of handles that allows to have asynchronous operation without blocking: use tokio; #[derive(Clone)] struct Cont { delta: usize, } impl Cont { fn get(&mut self) -> usize { self.delta …
-1
votes
2 answers

How to serialize SEC1 encoded ECDSA public key to ASN.1 DER format with Rust?

I have written the Python version of the conversion method, but the Rust version I don't know how to write, Rust cannot be written using the openssl package, I query the data and it seems to be available k256="0.13.1" der = "0.7.5" replace Currently…
hewm
  • 5
  • 5
-1
votes
1 answer

Reuseable async-closures/functions in a Hashmap or alike, Rust

I want to create a struct of which has four methods: new(), handle_interaction(), add_shortcut(), async start_server() The struct should contain a web server, which is started using the async start_server(), a list of available shortcuts…
-1
votes
1 answer

How to trim a BytesMut from bytes crate?

Suppose I have a BytesMut, I want to be able to make it trim_bytes. let some_bytes = BytesMut::from(" hello world "); let trim_bytes = some_bytes.some_trim_method(); // trim_bytes = BytesMut::From("hello world"); some_trim_method() is what…
-1
votes
1 answer

no method named `incoming` found for struct `tokio::net::TcpListener`

I am writing a tcp echo server using tower and tokio. However, I am unable to use the method incoming for tokio::net::TcpListener /* [dependencies] futures = "0.3" tokio = { version = "1", features = ["full"] } tower = { version = "0.4", features =…
Blank
  • 423
  • 1
  • 5
  • 16
-1
votes
1 answer

browser does't receive the reponse that tokio TcpStream write

i tried use tokio(tokio={version="1", features=["full"]}) to implement a simple http server. The code is below. The weired thing is the server can receive the request from browser, but the brower can't receive the response from the server. Is there…
Keith
  • 807
  • 7
  • 13
-1
votes
1 answer

Accessing main-scoped awaitable hashmap from within a task without using channels

I am checking out WebSocket frameworks for Rust and ended up watching a tutorial video on Warp (https://www.youtube.com/watch?v=fuiFycJpCBw), recreated that project and then compared it with Warp's own example implementation of a chat server. I…
Daniel F
  • 13,684
  • 11
  • 87
  • 116
-1
votes
2 answers

Why is the performance of rust tokio so poor? [release test result updated]

The following scenarios are frequently used in asynchronous programming. channel tx/rx; mutex lock/unlock; async task spawn; So I ran some comparison tests on a lower performance cloud host (equivalent to j1900) as follows. I found that the…
progquester
  • 1,228
  • 14
  • 23
-1
votes
1 answer

Rust value updatable across tokio threads

I'd like to keep track of a mutable number across multiple threads. I want to pass this incrementable number (u32) to multiple tokio tasks, each of which can increment it and inspect the value in a safe way. What is the proper data structure for…
Test
  • 962
  • 9
  • 26
-1
votes
2 answers

Tokio macro requires rt or rt-multi-thread in Solana program

Anyone able to guide me on why I can be getting this error on my tests? The #[tokio::test] macro requires rt or rt-multi-thread. It is more a Rust question than a Solana one, but I have been following the examples (and I am learning Rust), so just…
awesomeQ
  • 11
  • 2
-1
votes
1 answer

confusion about tokio/bytes::BytesMut

from the doc: BytesMut represents a unique view into a potentially shared memory region. Given the uniqueness guarantee, owners of BytesMut handles are able to mutate the memory. BytesMut can be thought of as containing a buf: Arc, an offset…
linuxfish
  • 89
  • 1
  • 8
-1
votes
1 answer

why am i getting an error that is running for others in rust reqwest?

I an trying to build a webscraper via rust using reqwest library. reqwest = "0.11.10" scraper = "0.12.0" I saw the example here: https://kadekillary.work/post/webscraping-rust/ I tried to do the same thing, but i am getting an error. My code: ` …
-1
votes
2 answers

Why do we need to await?

The following piece of code is taken from the tokio crate tutorial use tokio::io::{self, AsyncWriteExt}; use tokio::fs::File; #[tokio::main] async fn main() -> io::Result<()> { let mut file = File::create("foo.txt").await?; // Writes some…
storm
  • 795
  • 1
  • 5
  • 12