From 751c122589cfd9935e8e3239cd0d692e573784c5 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 19 Nov 2020 16:23:32 -0800 Subject: [PATCH] feat(lib): update `bytes` to 0.6, update `http-body` (#2339) This branch updates `bytes` and `http-body` to the latest versions. The `http-body` version that uses `bytes` 0.6 hasn't been released yet, so we depend on it via a git dep for now. Presumably Hyper and `http-body` will synchronize their releases. Other than that, this is a pretty mechanical update. Should fix the build and unblock the `h2` update to use vectored writes. --- Cargo.toml | 6 +++--- examples/client_json.rs | 2 +- examples/web_api.rs | 2 +- src/body/to_bytes.rs | 2 +- src/proto/h1/encode.rs | 2 +- src/proto/h1/io.rs | 6 +++++- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bcedfca437..03b691c9d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,12 +22,12 @@ include = [ ] [dependencies] -bytes = "0.5" +bytes = "0.6" futures-core = { version = "0.3", default-features = false } futures-channel = "0.3" futures-util = { version = "0.3", default-features = false } http = "0.2" -http-body = "0.3.1" +http-body = { git = "https://github.com/hyperium/http-body" } httpdate = "0.3" httparse = "1.0" h2 = { git = "https://github.com/hyperium/h2", optional = true } @@ -63,7 +63,7 @@ tokio = { version = "0.3", features = [ "test-util", ] } tokio-test = "0.3" -tokio-util = { version = "0.4", features = ["codec"] } +tokio-util = { version = "0.5", features = ["codec"] } tower-util = "0.3" url = "1.0" diff --git a/examples/client_json.rs b/examples/client_json.rs index 63dc4bff88..5bb585b935 100644 --- a/examples/client_json.rs +++ b/examples/client_json.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate serde_derive; -use bytes::buf::BufExt as _; +use bytes::Buf as _; use hyper::Client; // A simple type alias so as to DRY. diff --git a/examples/web_api.rs b/examples/web_api.rs index bc9e13787d..5226249b35 100644 --- a/examples/web_api.rs +++ b/examples/web_api.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -use bytes::buf::BufExt; +use bytes::Buf; use futures_util::{stream, StreamExt}; use hyper::client::HttpConnector; use hyper::service::{make_service_fn, service_fn}; diff --git a/src/body/to_bytes.rs b/src/body/to_bytes.rs index 4cce7857d7..8dfbe01cc3 100644 --- a/src/body/to_bytes.rs +++ b/src/body/to_bytes.rs @@ -23,7 +23,7 @@ where let second = if let Some(buf) = body.data().await { buf? } else { - return Ok(first.to_bytes()); + return Ok(first.copy_to_bytes(first.bytes().len())); }; // With more than 1 buf, we gotta flatten into a Vec first. diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index 9a80c8f3c7..d165527ea9 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -1,7 +1,7 @@ use std::fmt; use std::io::IoSlice; -use bytes::buf::ext::{BufExt, Chain, Take}; +use bytes::buf::{Chain, Take}; use bytes::Buf; use super::io::WriteBuf; diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index bfe1c4c3f9..04dcfbcc6e 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -3,6 +3,7 @@ use std::cmp; use std::fmt; use std::io::{self, IoSlice}; use std::marker::Unpin; +use std::mem::MaybeUninit; use bytes::{Buf, BufMut, Bytes, BytesMut}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; @@ -191,7 +192,10 @@ where if self.read_buf_remaining_mut() < next { self.read_buf.reserve(next); } - let mut buf = ReadBuf::uninit(&mut self.read_buf.bytes_mut()[..]); + + let dst = self.read_buf.bytes_mut(); + let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit]) }; + let mut buf = ReadBuf::uninit(dst); match Pin::new(&mut self.io).poll_read(cx, &mut buf) { Poll::Ready(Ok(_)) => { let n = buf.filled().len();