Put Stream APIs behind unstable-stream feature
This commit is contained in:
		| @@ -5,7 +5,6 @@ use std::task::{Context, Poll}; | ||||
|  | ||||
| use bytes::Bytes; | ||||
| use futures_core::Stream; | ||||
| use futures_util::TryStreamExt; | ||||
| use http_body::Body as HttpBody; | ||||
| use tokio::timer::Delay; | ||||
|  | ||||
| @@ -55,12 +54,28 @@ impl Body { | ||||
|     /// let body = Body::wrap_stream(stream); | ||||
|     /// # } | ||||
|     /// ``` | ||||
|     /// | ||||
|     /// # Unstable | ||||
|     /// | ||||
|     /// This requires the `unstable-stream` feature to be enabled. | ||||
|     #[cfg(feature = "unstable-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>>, | ||||
|         hyper::Chunk: 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>>, | ||||
|         hyper::Chunk: From<S::Ok>, | ||||
|     { | ||||
|         use futures_util::TryStreamExt; | ||||
|  | ||||
|         let body = Box::pin(WrapStream( | ||||
|             stream.map_ok(hyper::Chunk::from).map_err(Into::into), | ||||
|         )); | ||||
|   | ||||
| @@ -121,7 +121,7 @@ impl Form { | ||||
|         let last = stream::once(future::ready(Ok( | ||||
|             format!("--{}--\r\n", self.boundary()).into() | ||||
|         ))); | ||||
|         Body::wrap_stream(stream.chain(last)) | ||||
|         Body::stream(stream.chain(last)) | ||||
|     } | ||||
|  | ||||
|     /// Generate a hyper::Body stream for a single Part instance of a Form request. | ||||
| @@ -505,7 +505,7 @@ mod tests { | ||||
|         let mut form = Form::new() | ||||
|             .part( | ||||
|                 "reader1", | ||||
|                 Part::stream(Body::wrap_stream(stream::once(future::ready::< | ||||
|                 Part::stream(Body::stream(stream::once(future::ready::< | ||||
|                     Result<String, crate::Error>, | ||||
|                 >(Ok( | ||||
|                     "part1".to_owned(), | ||||
| @@ -515,7 +515,7 @@ mod tests { | ||||
|             .part("key2", Part::text("value2").mime(mime::IMAGE_BMP)) | ||||
|             .part( | ||||
|                 "reader2", | ||||
|                 Part::stream(Body::wrap_stream(stream::once(future::ready::< | ||||
|                 Part::stream(Body::stream(stream::once(future::ready::< | ||||
|                     Result<String, crate::Error>, | ||||
|                 >(Ok( | ||||
|                     "part2".to_owned(), | ||||
|   | ||||
| @@ -394,7 +394,7 @@ impl<T: Into<Body>> From<http::Response<T>> for Response { | ||||
| /// A `Response` can be piped as the `Body` of another request. | ||||
| impl From<Response> for Body { | ||||
|     fn from(r: Response) -> Body { | ||||
|         Body::wrap_stream(r.body) | ||||
|         Body::stream(r.body) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user