From d5efcd306cee5cc36bc5d09e5d836676f806d3af Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 27 Dec 2023 18:02:45 -0500 Subject: [PATCH] warnings gone --- src/async_impl/body.rs | 39 ++++++++++++++++++++------------------ src/async_impl/decoder.rs | 2 ++ src/async_impl/response.rs | 10 +++++----- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index fd3aaa53a..e5879b19e 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -19,9 +19,7 @@ pub struct Body { enum Inner { Reusable(Bytes), - Streaming { - body: BoxBody>, - }, + Streaming(BoxBody>), } /// A body with a total timeout. @@ -40,7 +38,7 @@ impl Body { pub fn as_bytes(&self) -> Option<&[u8]> { match &self.inner { Inner::Reusable(bytes) => Some(bytes.as_ref()), - Inner::Streaming { .. } => None, + Inner::Streaming(..) => None, } } @@ -70,15 +68,6 @@ impl Body { #[cfg(feature = "stream")] #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] pub fn wrap_stream(stream: S) -> Body - where - S: futures_core::stream::TryStream + Send + Sync + 'static, - S::Error: Into>, - Bytes: From, - { - Body::stream(stream) - } - - pub(crate) fn stream(stream: S) -> Body where S: futures_core::stream::TryStream + Send + Sync + 'static, S::Error: Into>, @@ -92,9 +81,7 @@ impl Body { stream.map_ok(|d| Frame::data(Bytes::from(d))).map_err(Into::into), )); Body { - inner: Inner::Streaming { - body, - }, + inner: Inner::Streaming(body), } } @@ -119,6 +106,22 @@ impl Body { } } + // pub? + pub(crate) fn streaming(inner: B) -> Body + where + B: HttpBody + Send + Sync + 'static, + B::Data: Into, + B::Error: Into>, + { + use http_body_util::BodyExt; + + let boxed = inner.map_frame(|f| f.map_data(Into::into)).map_err(Into::into).boxed(); + + Body { + inner: Inner::Streaming(boxed), + } + } + pub(crate) fn try_reuse(self) -> (Option, Self) { let reuse = match self.inner { Inner::Reusable(ref chunk) => Some(chunk.clone()), @@ -145,7 +148,7 @@ impl Body { pub(crate) fn content_length(&self) -> Option { match self.inner { Inner::Reusable(ref bytes) => Some(bytes.len() as u64), - Inner::Streaming { ref body, .. } => body.size_hint().exact(), + Inner::Streaming(ref body) => body.size_hint().exact(), } } } @@ -230,7 +233,7 @@ impl HttpBody for Body { Poll::Ready(Some(Ok(hyper::body::Frame::data(out)))) } }, - Inner::Streaming { ref mut body } => { + Inner::Streaming(ref mut body) => { Poll::Ready(futures_core::ready!(Pin::new(body).poll_frame(cx)) .map(|opt_chunk| opt_chunk.map_err(crate::error::body))) } diff --git a/src/async_impl/decoder.rs b/src/async_impl/decoder.rs index 2dd300b90..8ce50e75a 100644 --- a/src/async_impl/decoder.rs +++ b/src/async_impl/decoder.rs @@ -351,6 +351,7 @@ impl Stream for IoStream { // ===== impl Accepts ===== impl Accepts { + /* pub(super) fn none() -> Self { Accepts { #[cfg(feature = "gzip")] @@ -361,6 +362,7 @@ impl Accepts { deflate: false, } } + */ pub(super) fn as_str(&self) -> Option<&'static str> { match (self.is_gzip(), self.is_brotli(), self.is_deflate()) { diff --git a/src/async_impl/response.rs b/src/async_impl/response.rs index 30cc33e3a..a9071026f 100644 --- a/src/async_impl/response.rs +++ b/src/async_impl/response.rs @@ -405,10 +405,11 @@ impl fmt::Debug for Response { } } +/* +// I'm not sure this conversion is that useful... People should be encouraged +// to use `http::Resposne`, not `reqwest::Response`. impl> From> for Response { fn from(r: http::Response) -> Response { - todo!() - /* use crate::response::ResponseUrl; let (mut parts, body) = r.into_parts(); @@ -424,15 +425,14 @@ impl> From> for Response { res, url: Box::new(url), } - */ } } +*/ /// A `Response` can be piped as the `Body` of another request. impl From for Body { fn from(r: Response) -> Body { - todo!() - //Body::stream(r.res.into_body()) + Body::streaming(r.res.into_body()) } }