diff --git a/src/body.rs b/src/body.rs index 5817565c..e7c5cc2e 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,4 +1,4 @@ -use futures_lite::{io, prelude::*, ready}; +use futures_lite::{io, prelude::*, ready, AsyncRead}; use serde::{de::DeserializeOwned, Serialize}; use std::fmt::{self, Debug}; @@ -12,7 +12,7 @@ pin_project_lite::pin_project! { /// A streaming HTTP body. /// /// `Body` represents the HTTP body of both `Request` and `Response`. It's completely - /// streaming, and implements `AsyncBufRead` to make reading from it both convenient and + /// streaming, and implements `AsyncRead` to make reading from it both convenient and /// performant. /// /// Both `Request` and `Response` take `Body` by `Into`, which means that passing string @@ -53,7 +53,7 @@ pin_project_lite::pin_project! { /// and not rely on the fallback mechanisms. However, they're still there if you need them. pub struct Body { #[pin] - reader: Box, + reader: Box, mime: Mime, length: Option, bytes_read: usize @@ -103,7 +103,7 @@ impl Body { /// req.set_body(Body::from_reader(cursor, Some(len))); /// ``` pub fn from_reader( - reader: impl AsyncBufRead + Unpin + Send + Sync + 'static, + reader: impl AsyncRead + Unpin + Send + Sync + 'static, len: Option, ) -> Self { Self { @@ -127,7 +127,7 @@ impl Body { /// let body = Body::from_reader(cursor, None); /// let _ = body.into_reader(); /// ``` - pub fn into_reader(self) -> Box { + pub fn into_reader(self) -> Box { self.reader } @@ -383,7 +383,7 @@ impl Body { Ok(Self { mime, length: Some(len as usize), - reader: Box::new(io::BufReader::new(file)), + reader: Box::new(file), bytes_read: 0, }) } @@ -483,17 +483,6 @@ impl AsyncRead for Body { } } -impl AsyncBufRead for Body { - #[allow(missing_doc_code_examples)] - fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.project().reader.poll_fill_buf(cx) - } - - fn consume(mut self: Pin<&mut Self>, amt: usize) { - Pin::new(&mut self.reader).consume(amt) - } -} - /// Look at first few bytes of a file to determine the mime type. /// This is used for various binary formats such as images and videos. #[cfg(all(feature = "fs", not(target_os = "unknown")))] diff --git a/src/lib.rs b/src/lib.rs index c332fb54..0b3c168a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ //! there are many different possible `Mime` types. //! //! `http-types`' `Body` struct can take anything that implements -//! [`AsyncBufRead`](https://docs.rs/futures/0.3.1/futures/io/trait.AsyncBufRead.html) and stream +//! [`AsyncRead`](https://docs.rs/futures/0.3.1/futures/io/trait.AsyncRead.html) and stream //! it out. Depending on the version of HTTP used, the underlying bytes will be transmitted //! differently. As a rule, if you know the size of the body it's usually more efficient to //! declare it up front. But if you don't, things will still work. diff --git a/src/request.rs b/src/request.rs index 2296cc32..84471ff9 100644 --- a/src/request.rs +++ b/src/request.rs @@ -892,18 +892,6 @@ impl AsyncRead for Request { } } -impl AsyncBufRead for Request { - #[allow(missing_doc_code_examples)] - fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.project(); - this.body.poll_fill_buf(cx) - } - - fn consume(mut self: Pin<&mut Self>, amt: usize) { - Pin::new(&mut self.body).consume(amt) - } -} - impl AsRef for Request { fn as_ref(&self) -> &Headers { &self.headers diff --git a/src/response.rs b/src/response.rs index 766dacba..e1a6bd21 100644 --- a/src/response.rs +++ b/src/response.rs @@ -603,18 +603,6 @@ impl AsyncRead for Response { } } -impl AsyncBufRead for Response { - #[allow(missing_doc_code_examples)] - fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.project(); - this.body.poll_fill_buf(cx) - } - - fn consume(mut self: Pin<&mut Self>, amt: usize) { - Pin::new(&mut self.body).consume(amt) - } -} - impl AsRef for Response { fn as_ref(&self) -> &Headers { &self.headers