@@ -11,9 +11,10 @@ Let's tell Cargo about our dependencies by having this in the Cargo.toml.
1111
1212``` toml
1313[dependencies ]
14- hyper = { version = " 1.0.0-rc.3 " , features = [" full" ] }
14+ hyper = { version = " 1.0.0-rc.4 " , features = [" full" ] }
1515tokio = { version = " 1" , features = [" full" ] }
16- http-body-util = " 0.1.0-rc.2"
16+ http-body-util = " 0.1.0-rc.3"
17+ hyper-util = { git = " https://github.com/hyperium/hyper-util.git" }
1718```
1819
1920Now, we need to import pieces to use from our dependencies:
@@ -22,9 +23,11 @@ Now, we need to import pieces to use from our dependencies:
2223# extern crate http_body_util;
2324# extern crate hyper;
2425# extern crate tokio;
26+ # extern crate hyper_util;
2527use http_body_util :: Empty ;
2628use hyper :: Request ;
2729use hyper :: body :: Bytes ;
30+ use hyper_util :: rt :: TokioIo ;
2831use tokio :: net :: TcpStream ;
2932# fn main () {}
3033```
@@ -74,10 +77,12 @@ setup we'll spawn a `tokio::task` and `await` it.
7477``` rust
7578# extern crate http_body_util;
7679# extern crate hyper;
80+ # extern crate hyper_util;
7781# extern crate tokio;
7882# use http_body_util :: Empty ;
7983# use hyper :: body :: Bytes ;
8084# use hyper :: Request ;
85+ # use hyper_util :: rt :: TokioIo ;
8186# use tokio :: net :: TcpStream ;
8287# async fn run () -> Result <(), Box <dyn std :: error :: Error + Send + Sync >> {
8388// Parse our URL...
@@ -92,8 +97,12 @@ let address = format!("{}:{}", host, port);
9297// Open a TCP connection to the remote host
9398let stream = TcpStream :: connect (address ). await ? ;
9499
100+ // Use an adapter to access something implementing `tokio::io` traits as if they implement
101+ // `hyper::rt` IO traits.
102+ let io = TokioIo :: new (stream );
103+
95104// Perform a TCP handshake
96- let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (stream ). await ? ;
105+ let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (io ). await ? ;
97106
98107// Spawn a task to poll the connection, driving the HTTP state
99108tokio :: task :: spawn (async move {
@@ -126,18 +135,21 @@ status of the response to see that it returned the expected `200 OK` status.
126135``` rust
127136# extern crate http_body_util;
128137# extern crate hyper;
138+ # extern crate hyper_util;
129139# extern crate tokio;
130140# use http_body_util :: Empty ;
131141# use hyper :: body :: Bytes ;
132142# use hyper :: Request ;
143+ # use hyper_util :: rt :: TokioIo ;
133144# use tokio :: net :: TcpStream ;
134145# async fn run () -> Result <(), Box <dyn std :: error :: Error + Send + Sync >> {
135146# let url = " http://httpbin.org/ip" . parse :: <hyper :: Uri >()? ;
136147# let host = url . host (). expect (" uri has no host" );
137148# let port = url . port_u16 (). unwrap_or (80 );
138149# let addr = format! (" {}:{}" , host , port );
139150# let stream = TcpStream :: connect (addr ). await ? ;
140- # let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (stream ). await ? ;
151+ # let io = TokioIo :: new (stream );
152+ # let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (io ). await ? ;
141153# tokio :: task :: spawn (async move {
142154# if let Err (err ) = conn . await {
143155# println! (" Connection failed: {:?}" , err );
@@ -182,10 +194,12 @@ use tokio::io::{stdout, AsyncWriteExt as _};
182194``` rust
183195# extern crate http_body_util;
184196# extern crate hyper;
197+ # extern crate hyper_util;
185198# extern crate tokio;
186199# use http_body_util :: {BodyExt , Empty };
187200# use hyper :: body :: Bytes ;
188201# use hyper :: Request ;
202+ # use hyper_util :: rt :: TokioIo ;
189203# use tokio :: net :: TcpStream ;
190204# use tokio :: io :: {self , AsyncWriteExt as _};
191205# async fn run () -> Result <(), Box <dyn std :: error :: Error + Send + Sync >> {
@@ -194,7 +208,8 @@ use tokio::io::{stdout, AsyncWriteExt as _};
194208# let port = url . port_u16 (). unwrap_or (80 );
195209# let addr = format! (" {}:{}" , host , port );
196210# let stream = TcpStream :: connect (addr ). await ? ;
197- # let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (stream ). await ? ;
211+ # let io = TokioIo :: new (stream );
212+ # let (mut sender , conn ) = hyper :: client :: conn :: http1 :: handshake (io ). await ? ;
198213# tokio :: task :: spawn (async move {
199214# if let Err (err ) = conn . await {
200215# println! (" Connection failed: {:?}" , err );
0 commit comments