Asynchronous I/O in Rust
When it comes to I/O operations, there is a go-to crate. It's called tokio
, and it handles asynchronous input and output operations seamlessly. This crate is based in MIO. MIO, from Metal IO, is a base crate that provides a really low-level interface to asynchronous programming. It generates an event queue, and you can use a loop to gather all the events one by one, asynchronously.
As we saw earlier, these events can be anything from a TCP message was received to the file you requested is partially ready. There are tutorials to create small TCP servers in MIO, for example, but the idea of MIO is not using the crate directly, but using a facade. The most known and useful facade is the tokio
crate. This crate, by itself, only gives you some small primitives, but it opens the doors to many asynchronous interfaces. You have, for example, tokio-serial
, tokio-jsonrpc
, tokio-http2
, tokio-imap
, and many, many more.
Not only that, you have also utilities such as tokio-retry...