Skip to content

Commit

Permalink
warnings gone
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 27, 2023
1 parent 38f64ba commit d5efcd3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
39 changes: 21 additions & 18 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub struct Body {

enum Inner {
Reusable(Bytes),
Streaming {
body: BoxBody<Bytes, Box<dyn std::error::Error + Send + Sync>>,
},
Streaming(BoxBody<Bytes, Box<dyn std::error::Error + Send + Sync>>),
}

/// A body with a total timeout.
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -70,15 +68,6 @@ impl Body {
#[cfg(feature = "stream")]
#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
pub fn wrap_stream<S>(stream: S) -> Body
where
S: futures_core::stream::TryStream + Send + Sync + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Bytes: From<S::Ok>,
{
Body::stream(stream)
}

pub(crate) fn stream<S>(stream: S) -> Body
where
S: futures_core::stream::TryStream + Send + Sync + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Expand All @@ -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),
}
}

Expand All @@ -119,6 +106,22 @@ impl Body {
}
}

// pub?
pub(crate) fn streaming<B>(inner: B) -> Body
where
B: HttpBody + Send + Sync + 'static,
B::Data: Into<Bytes>,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
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<Bytes>, Self) {
let reuse = match self.inner {
Inner::Reusable(ref chunk) => Some(chunk.clone()),
Expand All @@ -145,7 +148,7 @@ impl Body {
pub(crate) fn content_length(&self) -> Option<u64> {
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(),
}
}
}
Expand Down Expand Up @@ -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)))
}
Expand Down
2 changes: 2 additions & 0 deletions src/async_impl/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ impl Stream for IoStream {
// ===== impl Accepts =====

impl Accepts {
/*
pub(super) fn none() -> Self {
Accepts {
#[cfg(feature = "gzip")]
Expand All @@ -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()) {
Expand Down
10 changes: 5 additions & 5 deletions src/async_impl/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<Body>> From<http::Response<T>> for Response {
fn from(r: http::Response<T>) -> Response {
todo!()
/*
use crate::response::ResponseUrl;
let (mut parts, body) = r.into_parts();
Expand All @@ -424,15 +425,14 @@ impl<T: Into<Body>> From<http::Response<T>> for Response {
res,
url: Box::new(url),
}
*/
}
}
*/

/// A `Response` can be piped as the `Body` of another request.
impl From<Response> for Body {
fn from(r: Response) -> Body {
todo!()
//Body::stream(r.res.into_body())
Body::streaming(r.res.into_body())
}
}

Expand Down

0 comments on commit d5efcd3

Please sign in to comment.