|
1 |
| -//! Tokio IO integration for hyper |
| 1 | +//! [`tokio`] runtime components integration for [`hyper`]. |
| 2 | +//! |
| 3 | +//! [`hyper::rt`] exposes a set of traits to allow hyper to be agnostic to |
| 4 | +//! its underlying asynchronous runtime. This submodule provides glue for |
| 5 | +//! [`tokio`] users to bridge those types to [`hyper`]'s interfaces. |
| 6 | +//! |
| 7 | +//! # IO |
| 8 | +//! |
| 9 | +//! [`hyper`] abstracts over asynchronous readers and writers using [`Read`] |
| 10 | +//! and [`Write`], while [`tokio`] abstracts over this using [`AsyncRead`] |
| 11 | +//! and [`AsyncWrite`]. This submodule provides a collection of IO adaptors |
| 12 | +//! to bridge these two IO ecosystems together: [`TokioIo<I>`], |
| 13 | +//! [`WithHyperIo<I>`], and [`WithTokioIo<I>`]. |
| 14 | +//! |
| 15 | +//! To compare and constrast these IO adaptors and to help explain which |
| 16 | +//! is the proper choice for your needs, here is a table showing which IO |
| 17 | +//! traits these implement, given two types `T` and `H` which implement |
| 18 | +//! Tokio's and Hyper's corresponding IO traits: |
| 19 | +//! |
| 20 | +//! | | [`AsyncRead`] | [`AsyncWrite`] | [`Read`] | [`Write`] | |
| 21 | +//! |--------------------|------------------|-------------------|--------------|--------------| |
| 22 | +//! | `T` | ✅ **true** | ✅ **true** | ❌ **false** | ❌ **false** | |
| 23 | +//! | `H` | ❌ **false** | ❌ **false** | ✅ **true** | ✅ **true** | |
| 24 | +//! | [`TokioIo<T>`] | ❌ **false** | ❌ **false** | ✅ **true** | ✅ **true** | |
| 25 | +//! | [`TokioIo<H>`] | ✅ **true** | ✅ **true** | ❌ **false** | ❌ **false** | |
| 26 | +//! | [`WithHyperIo<T>`] | ✅ **true** | ✅ **true** | ✅ **true** | ✅ **true** | |
| 27 | +//! | [`WithHyperIo<H>`] | ❌ **false** | ❌ **false** | ❌ **false** | ❌ **false** | |
| 28 | +//! | [`WithTokioIo<T>`] | ❌ **false** | ❌ **false** | ❌ **false** | ❌ **false** | |
| 29 | +//! | [`WithTokioIo<H>`] | ✅ **true** | ✅ **true** | ✅ **true** | ✅ **true** | |
| 30 | +//! |
| 31 | +//! For most situations, [`TokioIo<I>`] is the proper choice. This should be |
| 32 | +//! constructed, wrapping some underlying [`hyper`] or [`tokio`] IO, at the |
| 33 | +//! call-site of a function like [`hyper::client::conn::http1::handshake`]. |
| 34 | +//! |
| 35 | +//! [`TokioIo<I>`] switches across these ecosystems, but notably does not |
| 36 | +//! preserve the existing IO trait implementations of its underlying IO. If |
| 37 | +//! one wishes to _extend_ IO with additional implementations, |
| 38 | +//! [`WithHyperIo<I>`] and [`WithTokioIo<I>`] are the correct choice. |
| 39 | +//! |
| 40 | +//! For example, a Tokio reader/writer can be wrapped in [`WithHyperIo<I>`]. |
| 41 | +//! That will implement _both_ sets of IO traits. Conversely, |
| 42 | +//! [`WithTokioIo<I>`] will implement both sets of IO traits given a |
| 43 | +//! reader/writer that implements Hyper's [`Read`] and [`Write`]. |
| 44 | +//! |
| 45 | +//! See [`tokio::io`] and ["_Asynchronous IO_"][tokio-async-docs] for more |
| 46 | +//! information. |
| 47 | +//! |
| 48 | +//! [`AsyncRead`]: tokio::io::AsyncRead |
| 49 | +//! [`AsyncWrite`]: tokio::io::AsyncWrite |
| 50 | +//! [`Read`]: hyper::rt::Read |
| 51 | +//! [`Write`]: hyper::rt::Write |
| 52 | +//! [tokio-async-docs]: https://docs.rs/tokio/latest/tokio/#asynchronous-io |
| 53 | +
|
2 | 54 | use std::{
|
3 | 55 | future::Future,
|
4 | 56 | pin::Pin,
|
|
0 commit comments