Module tokio

Source
Available on crate feature tokio only.
Expand description

tokio runtime components integration for hyper.

hyper::rt exposes a set of traits to allow hyper to be agnostic to its underlying asynchronous runtime. This submodule provides glue for tokio users to bridge those types to hyper’s interfaces.

§IO

hyper abstracts over asynchronous readers and writers using Read and Write, while tokio abstracts over this using AsyncRead and AsyncWrite. This submodule provides a collection of IO adaptors to bridge these two IO ecosystems together: TokioIo<I>, WithHyperIo<I>, and WithTokioIo<I>.

To compare and constrast these IO adaptors and to help explain which is the proper choice for your needs, here is a table showing which IO traits these implement, given two types T and H which implement Tokio’s and Hyper’s corresponding IO traits:

AsyncReadAsyncWriteReadWrite
Ttruetruefalsefalse
Hfalsefalsetruetrue
TokioIo<T>falsefalsetruetrue
TokioIo<H>truetruefalsefalse
WithHyperIo<T>truetruetruetrue
WithHyperIo<H>falsefalsefalsefalse
WithTokioIo<T>falsefalsefalsefalse
WithTokioIo<H>truetruetruetrue

For most situations, TokioIo<I> is the proper choice. This should be constructed, wrapping some underlying hyper or tokio IO, at the call-site of a function like hyper::client::conn::http1::handshake.

TokioIo<I> switches across these ecosystems, but notably does not preserve the existing IO trait implementations of its underlying IO. If one wishes to extend IO with additional implementations, WithHyperIo<I> and WithTokioIo<I> are the correct choice.

For example, a Tokio reader/writer can be wrapped in WithHyperIo<I>. That will implement both sets of IO traits. Conversely, WithTokioIo<I> will implement both sets of IO traits given a reader/writer that implements Hyper’s Read and Write.

See tokio::io and Asynchronous IO for more information.

Structs§

TokioExecutor
Future executor that utilises tokio threads.
TokioIo
A wrapper that implements Tokio’s IO traits for an inner type that implements hyper’s IO traits, or vice versa (implements hyper’s IO traits for a type that implements Tokio’s IO traits).
TokioTimer
A Timer that uses the tokio runtime.
WithHyperIo
Extends an underlying tokio I/O with hyper I/O implementations.
WithTokioIo
Extends an underlying hyper I/O with tokio I/O implementations.