
# 1.17.0 (February 16, 2022) This release updates the minimum supported Rust version (MSRV) to 1.49, the `mio` dependency to v0.8, and the (optional) `parking_lot` dependency to v0.12. Additionally, it contains several bug fixes, as well as internal refactoring and performance improvements. ### Fixed - time: prevent panicking in `sleep` with large durations ([#4495]) - time: eliminate potential panics in `Instant` arithmetic on platforms where `Instant::now` is not monotonic ([#4461]) - io: fix `DuplexStream` not participating in cooperative yielding ([#4478]) - rt: fix potential double panic when dropping a `JoinHandle` ([#4430]) ### Changed - update minimum supported Rust version to 1.49 ([#4457]) - update `parking_lot` dependency to v0.12.0 ([#4459]) - update `mio` dependency to v0.8 ([#4449]) - rt: remove an unnecessary lock in the blocking pool ([#4436]) - rt: remove an unnecessary enum in the basic scheduler ([#4462]) - time: use bit manipulation instead of modulo to improve performance ([#4480]) - net: use `std::future::Ready` instead of our own `Ready` future ([#4271]) - replace deprecated `atomic::spin_loop_hint` with `hint::spin_loop` ([#4491]) - fix miri failures in intrusive linked lists ([#4397]) ### Documented - io: add an example for `tokio::process::ChildStdin` ([#4479]) ### Unstable The following changes only apply when building with `--cfg tokio_unstable`: - task: fix missing location information in `tracing` spans generated by `spawn_local` ([#4483]) - task: add `JoinSet` for managing sets of tasks ([#4335]) - metrics: fix compilation error on MIPS ([#4475]) - metrics: fix compilation error on arm32v7 ([#4453]) [#4495]: https://github.com/tokio-rs/tokio/pull/4495 [#4461]: https://github.com/tokio-rs/tokio/pull/4461 [#4478]: https://github.com/tokio-rs/tokio/pull/4478 [#4430]: https://github.com/tokio-rs/tokio/pull/4430 [#4457]: https://github.com/tokio-rs/tokio/pull/4457 [#4459]: https://github.com/tokio-rs/tokio/pull/4459 [#4449]: https://github.com/tokio-rs/tokio/pull/4449 [#4462]: https://github.com/tokio-rs/tokio/pull/4462 [#4436]: https://github.com/tokio-rs/tokio/pull/4436 [#4480]: https://github.com/tokio-rs/tokio/pull/4480 [#4271]: https://github.com/tokio-rs/tokio/pull/4271 [#4491]: https://github.com/tokio-rs/tokio/pull/4491 [#4397]: https://github.com/tokio-rs/tokio/pull/4397 [#4479]: https://github.com/tokio-rs/tokio/pull/4479 [#4483]: https://github.com/tokio-rs/tokio/pull/4483 [#4335]: https://github.com/tokio-rs/tokio/pull/4335 [#4475]: https://github.com/tokio-rs/tokio/pull/4475 [#4453]: https://github.com/tokio-rs/tokio/pull/4453
7.2 KiB
Tokio
A runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. It is:
-
Fast: Tokio's zero-cost abstractions give you bare-metal performance.
-
Reliable: Tokio leverages Rust's ownership, type system, and concurrency model to reduce bugs and ensure thread safety.
-
Scalable: Tokio has a minimal footprint, and handles backpressure and cancellation naturally.
Website | Guides | API Docs | Chat
Overview
Tokio is an event-driven, non-blocking I/O platform for writing asynchronous applications with the Rust programming language. 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.
These components provide the runtime components necessary for building an asynchronous application.
Example
A basic TCP echo server with Tokio.
Make sure you activated the full features of the tokio crate on Cargo.toml:
[dependencies]
tokio = { version = "1.17.0", features = ["full"] }
Then, on your main.rs:
use tokio::net::TcpListener;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let listener = TcpListener::bind("127.0.0.1:8080").await?;
loop {
let (mut socket, _) = listener.accept().await?;
tokio::spawn(async move {
let mut buf = [0; 1024];
// In a loop, read data from the socket and write the data back.
loop {
let n = match socket.read(&mut buf).await {
// socket closed
Ok(n) if n == 0 => return,
Ok(n) => n,
Err(e) => {
eprintln!("failed to read from socket; err = {:?}", e);
return;
}
};
// Write the data back
if let Err(e) = socket.write_all(&buf[0..n]).await {
eprintln!("failed to write to socket; err = {:?}", e);
return;
}
}
});
}
}
More examples can be found here. For a larger "real world" example, see the mini-redis repository.
To see a list of the available features flags that can be enabled, check our docs.
Getting Help
First, see if the answer to your question can be found in the Guides or the API documentation. If the answer is not there, there is an active community in the Tokio Discord server. We would be happy to try to answer your question. You can also ask your question on the discussions page.
Contributing
🎈 Thanks for your help improving the project! We are so happy to have you! We have a contributing guide to help you get involved in the Tokio project.
Related Projects
In addition to the crates in this repository, the Tokio project also maintains several other libraries, including:
-
hyper
: A fast and correct HTTP/1.1 and HTTP/2 implementation for Rust. -
tonic
: A gRPC over HTTP/2 implementation focused on high performance, interoperability, and flexibility. -
warp
: A super-easy, composable, web server framework for warp speeds. -
tower
: A library of modular and reusable components for building robust networking clients and servers. -
tracing
(formerlytokio-trace
): A framework for application-level tracing and async-aware diagnostics. -
rdbc
: A Rust database connectivity library for MySQL, Postgres and SQLite. -
mio
: A low-level, cross-platform abstraction over OS I/O APIs that powerstokio
. -
bytes
: Utilities for working with bytes, including efficient byte buffers. -
loom
: A testing tool for concurrent Rust code
Supported Rust Versions
Tokio will keep a rolling MSRV (minimum supported rust version) policy of at least 6 months. When increasing the MSRV, the new Rust version must have been released at least six months ago. The current MSRV is 1.49.0.
Release schedule
Tokio doesn't follow a fixed release schedule, but we typically make one to two new minor releases each month. We make patch releases for bugfixes as necessary.
Bug patching policy
For the purposes of making patch releases with bugfixes, we have designated certain minor releases as LTS (long term support) releases. Whenever a bug warrants a patch release with a fix for the bug, it will be backported and released as a new patch release for each LTS minor version. Our current LTS releases are:
1.8.x
- LTS release until February 2022.1.14.x
- LTS release until June 2022.
Each LTS release will continue to receive backported fixes for at least half a year. If you wish to use a fixed minor release in your project, we recommend that you use an LTS release.
To use a fixed minor version, you can specify the version with a tilde. For
example, to specify that you wish to use the newest 1.8.x
patch release, you
can use the following dependency specification:
tokio = { version = "~1.8", features = [...] }
License
This project is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.