Prune the futures dependencies

This commit is contained in:
Constantin Nickel
2019-09-12 14:45:37 +02:00
committed by Sean McArthur
parent 5a337ba739
commit b1a90eb402
12 changed files with 54 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
use bytes::Bytes;
use futures::Stream;
use futures_core::Stream;
use hyper::body::Payload;
use std::fmt;
use std::future::Future;
@@ -30,7 +30,7 @@ impl Body {
///
/// ```
/// # use reqwest::Body;
/// # use futures;
/// # use futures_util;
/// # fn main() {
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec![
/// Ok("hello"),
@@ -38,14 +38,14 @@ impl Body {
/// Ok("world"),
/// ];
///
/// let stream = futures::stream::iter(chunks);
/// let stream = futures_util::stream::iter(chunks);
///
/// let body = Body::wrap_stream(stream);
/// # }
/// ```
pub fn wrap_stream<S>(stream: S) -> Body
where
S: futures::TryStream + Send + Sync + 'static,
S: futures_core::stream::TryStream + Send + Sync + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
hyper::Chunk: From<S::Ok>,
{
@@ -157,7 +157,7 @@ impl Stream for ImplStream {
return Poll::Ready(Some(Err(crate::error::timedout(None))));
}
}
futures::ready!(Pin::new(body).poll_data(cx))
futures_core::ready!(Pin::new(body).poll_data(cx))
.map(|opt_chunk| opt_chunk.map(Into::into).map_err(crate::error::from))
}
Inner::Reusable(ref mut bytes) => {

View File

@@ -19,8 +19,8 @@ use std::task::{Context, Poll};
use async_compression::stream::GzipDecoder;
use bytes::Bytes;
use futures::stream::Peekable;
use futures::Stream;
use futures_core::Stream;
use futures_util::stream::Peekable;
use hyper::header::{CONTENT_ENCODING, CONTENT_LENGTH, TRANSFER_ENCODING};
use hyper::HeaderMap;
@@ -80,7 +80,7 @@ impl Decoder {
///
/// This decoder will buffer and decompress chunks that are gzipped.
fn gzip(body: Body) -> Decoder {
use futures::stream::StreamExt;
use futures_util::StreamExt;
Decoder {
inner: Inner::Pending(Pending(IoStream(body.into_stream()).peekable())),
@@ -142,7 +142,7 @@ impl Stream for Decoder {
},
Inner::PlainText(ref mut body) => return Pin::new(body).poll_next(cx),
Inner::Gzip(ref mut decoder) => {
return match futures::ready!(Pin::new(decoder).poll_next(cx)) {
return match futures_core::ready!(Pin::new(decoder).poll_next(cx)) {
Some(Ok(bytes)) => Poll::Ready(Some(Ok(bytes))),
Some(Err(err)) => Poll::Ready(Some(Err(crate::error::from_io(err)))),
None => Poll::Ready(None),
@@ -159,17 +159,19 @@ impl Future for Pending {
type Output = Result<Inner, std::io::Error>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
use futures::stream::StreamExt;
use futures_util::StreamExt;
match futures::ready!(Pin::new(&mut self.0).peek(cx)) {
match futures_core::ready!(Pin::new(&mut self.0).peek(cx)) {
Some(Ok(_)) => {
// fallthrough
}
Some(Err(_e)) => {
// error was just a ref, so we need to really poll to move it
return Poll::Ready(Err(futures::ready!(Pin::new(&mut self.0).poll_next(cx))
.expect("just peeked Some")
.unwrap_err()));
return Poll::Ready(Err(futures_core::ready!(
Pin::new(&mut self.0).poll_next(cx)
)
.expect("just peeked Some")
.unwrap_err()));
}
None => return Poll::Ready(Ok(Inner::PlainText(Body::empty().into_stream()))),
};
@@ -186,7 +188,7 @@ impl Stream for IoStream {
type Item = Result<Bytes, std::io::Error>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
match futures::ready!(Pin::new(&mut self.0).poll_next(cx)) {
match futures_core::ready!(Pin::new(&mut self.0).poll_next(cx)) {
Some(Ok(chunk)) => Poll::Ready(Some(Ok(chunk))),
Some(Err(err)) => Poll::Ready(Some(Err(err.into_io()))),
None => Poll::Ready(None),

View File

@@ -7,7 +7,7 @@ use mime_guess::Mime;
use percent_encoding::{self, AsciiSet, NON_ALPHANUMERIC};
use uuid::Uuid;
use futures::StreamExt;
use futures_util::StreamExt;
use super::Body;
@@ -473,7 +473,8 @@ impl PercentEncoding {
#[cfg(test)]
mod tests {
use super::*;
use futures::TryStreamExt;
use futures_util::TryStreamExt;
use futures_util::{future, stream};
use tokio;
#[test]
@@ -493,17 +494,21 @@ mod tests {
let mut form = Form::new()
.part(
"reader1",
Part::stream(Body::wrap_stream(futures::stream::once(
futures::future::ready::<Result<String, crate::Error>>(Ok("part1".to_owned())),
))),
Part::stream(Body::wrap_stream(stream::once(future::ready::<
Result<String, crate::Error>,
>(Ok(
"part1".to_owned(),
))))),
)
.part("key1", Part::text("value1"))
.part("key2", Part::text("value2").mime(mime::IMAGE_BMP))
.part(
"reader2",
Part::stream(Body::wrap_stream(futures::stream::once(
futures::future::ready::<Result<String, crate::Error>>(Ok("part2".to_owned())),
))),
Part::stream(Body::wrap_stream(stream::once(future::ready::<
Result<String, crate::Error>,
>(Ok(
"part2".to_owned(),
))))),
)
.part("key3", Part::text("value3").file_name("filename"));
form.inner.boundary = "boundary".to_string();

View File

@@ -1,7 +1,7 @@
use std::fmt;
use std::future::Future;
use base64::encode;
use futures::Future;
use serde::Serialize;
use serde_json;
use serde_urlencoded;

View File

@@ -4,7 +4,7 @@ use std::net::SocketAddr;
use bytes::Bytes;
use encoding_rs::{Encoding, UTF_8};
use futures::{StreamExt, TryStreamExt};
use futures_util::{StreamExt, TryStreamExt};
use http;
use hyper::client::connect::HttpInfo;
use hyper::header::CONTENT_LENGTH;