1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-18 07:35:36 +00:00

web: Minimize futures dependencies

This commit is contained in:
Yuki Okushi 2020-05-18 11:47:20 +09:00
parent d7abbff3b0
commit a98e53ecb8
No known key found for this signature in database
GPG key ID: B0986C85C0E2DAA1
29 changed files with 60 additions and 51 deletions

View file

@ -84,7 +84,9 @@ awc = { version = "2.0.0-alpha.1", default-features = false }
bytes = "0.5.3" bytes = "0.5.3"
derive_more = "0.99.2" derive_more = "0.99.2"
encoding_rs = "0.8" encoding_rs = "0.8"
futures = "0.3.1" futures-channel = { version = "0.3.5", default-features = false }
futures-core = { version = "0.3.5", default-features = false }
futures-util = { version = "0.3.5", default-features = false }
fxhash = "0.2.1" fxhash = "0.2.1"
log = "0.4" log = "0.4"
mime = "0.3" mime = "0.3"

View file

@ -1,7 +1,7 @@
use actix_web::{test, web, App, HttpResponse}; use actix_web::{test, web, App, HttpResponse};
use awc::Client; use awc::Client;
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use futures::future::join_all; use futures_util::future::join_all;
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \ Hello World Hello World Hello World Hello World Hello World \

View file

@ -10,7 +10,7 @@ use actix_service::boxed::{self, BoxServiceFactory};
use actix_service::{ use actix_service::{
apply, apply_fn_factory, IntoServiceFactory, ServiceFactory, Transform, apply, apply_fn_factory, IntoServiceFactory, ServiceFactory, Transform,
}; };
use futures::future::FutureExt; use futures_util::future::FutureExt;
use crate::app_service::{AppEntry, AppInit, AppRoutingFactory}; use crate::app_service::{AppEntry, AppInit, AppRoutingFactory};
use crate::config::ServiceConfig; use crate::config::ServiceConfig;
@ -474,7 +474,7 @@ where
mod tests { mod tests {
use actix_service::Service; use actix_service::Service;
use bytes::Bytes; use bytes::Bytes;
use futures::future::{ok, err}; use futures_util::future::{ok, err};
use super::*; use super::*;
use crate::http::{header, HeaderValue, Method, StatusCode}; use crate::http::{header, HeaderValue, Method, StatusCode};

View file

@ -9,7 +9,7 @@ use actix_http::{Extensions, Request, Response};
use actix_router::{Path, ResourceDef, ResourceInfo, Router, Url}; use actix_router::{Path, ResourceDef, ResourceInfo, Router, Url};
use actix_service::boxed::{self, BoxService, BoxServiceFactory}; use actix_service::boxed::{self, BoxService, BoxServiceFactory};
use actix_service::{fn_service, Service, ServiceFactory}; use actix_service::{fn_service, Service, ServiceFactory};
use futures::future::{join_all, ok, FutureExt, LocalBoxFuture}; use futures_util::future::{join_all, ok, FutureExt, LocalBoxFuture};
use crate::config::{AppConfig, AppService}; use crate::config::{AppConfig, AppService};
use crate::data::{DataFactory, FnDataFactory}; use crate::data::{DataFactory, FnDataFactory};

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use actix_http::error::{Error, ErrorInternalServerError}; use actix_http::error::{Error, ErrorInternalServerError};
use actix_http::Extensions; use actix_http::Extensions;
use futures::future::{err, ok, LocalBoxFuture, Ready}; use futures_util::future::{err, ok, LocalBoxFuture, Ready};
use crate::dev::Payload; use crate::dev::Payload;
use crate::extract::FromRequest; use crate::extract::FromRequest;

View file

@ -4,7 +4,7 @@ use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use actix_http::error::Error; use actix_http::error::Error;
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
use crate::dev::Payload; use crate::dev::Payload;
use crate::request::HttpRequest; use crate::request::HttpRequest;
@ -50,7 +50,7 @@ pub trait FromRequest: Sized {
/// ```rust /// ```rust
/// use actix_web::{web, dev, App, Error, HttpRequest, FromRequest}; /// use actix_web::{web, dev, App, Error, HttpRequest, FromRequest};
/// use actix_web::error::ErrorBadRequest; /// use actix_web::error::ErrorBadRequest;
/// use futures::future::{ok, err, Ready}; /// use futures_util::future::{ok, err, Ready};
/// use serde_derive::Deserialize; /// use serde_derive::Deserialize;
/// use rand; /// use rand;
/// ///
@ -122,7 +122,7 @@ where
/// ```rust /// ```rust
/// use actix_web::{web, dev, App, Result, Error, HttpRequest, FromRequest}; /// use actix_web::{web, dev, App, Result, Error, HttpRequest, FromRequest};
/// use actix_web::error::ErrorBadRequest; /// use actix_web::error::ErrorBadRequest;
/// use futures::future::{ok, err, Ready}; /// use futures_util::future::{ok, err, Ready};
/// use serde_derive::Deserialize; /// use serde_derive::Deserialize;
/// use rand; /// use rand;
/// ///

View file

@ -6,8 +6,8 @@ use std::task::{Context, Poll};
use actix_http::{Error, Response}; use actix_http::{Error, Response};
use actix_service::{Service, ServiceFactory}; use actix_service::{Service, ServiceFactory};
use futures::future::{ok, Ready}; use futures_util::future::{ok, Ready};
use futures::ready; use futures_util::ready;
use pin_project::pin_project; use pin_project::pin_project;
use crate::extract::FromRequest; use crate::extract::FromRequest;

View file

@ -11,7 +11,7 @@ use actix_http::encoding::Encoder;
use actix_http::http::header::{ContentEncoding, ACCEPT_ENCODING}; use actix_http::http::header::{ContentEncoding, ACCEPT_ENCODING};
use actix_http::Error; use actix_http::Error;
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use futures::future::{ok, Ready}; use futures_util::future::{ok, Ready};
use pin_project::pin_project; use pin_project::pin_project;
use crate::dev::BodyEncoding; use crate::dev::BodyEncoding;
@ -133,7 +133,7 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project(); let this = self.project();
match futures::ready!(this.fut.poll(cx)) { match futures_util::ready!(this.fut.poll(cx)) {
Ok(resp) => { Ok(resp) => {
let enc = if let Some(enc) = resp.response().get_encoding() { let enc = if let Some(enc) = resp.response().get_encoding() {
enc enc

View file

@ -2,7 +2,7 @@
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use futures::future::{ok, Either, FutureExt, LocalBoxFuture}; use futures_util::future::{ok, Either, FutureExt, LocalBoxFuture};
/// `Middleware` for conditionally enables another middleware. /// `Middleware` for conditionally enables another middleware.
/// The controlled middleware must not change the `Service` interfaces. /// The controlled middleware must not change the `Service` interfaces.

View file

@ -4,7 +4,7 @@ use std::rc::Rc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE}; use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
use crate::http::{Error as HttpError, HeaderMap}; use crate::http::{Error as HttpError, HeaderMap};
@ -157,7 +157,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use actix_service::IntoService; use actix_service::IntoService;
use futures::future::ok; use futures_util::future::ok;
use super::*; use super::*;
use crate::dev::ServiceRequest; use crate::dev::ServiceRequest;

View file

@ -3,7 +3,7 @@ use std::rc::Rc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
use fxhash::FxHashMap; use fxhash::FxHashMap;
use crate::dev::{ServiceRequest, ServiceResponse}; use crate::dev::{ServiceRequest, ServiceResponse};
@ -147,7 +147,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use actix_service::IntoService; use actix_service::IntoService;
use futures::future::ok; use futures_util::future::ok;
use super::*; use super::*;
use crate::http::{header::CONTENT_TYPE, HeaderValue, StatusCode}; use crate::http::{header::CONTENT_TYPE, HeaderValue, StatusCode};

View file

@ -11,7 +11,7 @@ use std::task::{Context, Poll};
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use bytes::Bytes; use bytes::Bytes;
use futures::future::{ok, Ready}; use futures_util::future::{ok, Ready};
use log::debug; use log::debug;
use regex::Regex; use regex::Regex;
use time::OffsetDateTime; use time::OffsetDateTime;
@ -216,7 +216,7 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project(); let this = self.project();
let res = match futures::ready!(this.fut.poll(cx)) { let res = match futures_util::ready!(this.fut.poll(cx)) {
Ok(res) => res, Ok(res) => res,
Err(e) => return Poll::Ready(Err(e)), Err(e) => return Poll::Ready(Err(e)),
}; };
@ -506,7 +506,7 @@ impl<'a> fmt::Display for FormatDisplay<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use actix_service::{IntoService, Service, Transform}; use actix_service::{IntoService, Service, Transform};
use futures::future::ok; use futures_util::future::ok;
use super::*; use super::*;
use crate::http::{header, StatusCode}; use crate::http::{header, StatusCode};

View file

@ -4,7 +4,7 @@ use std::task::{Context, Poll};
use actix_http::http::{PathAndQuery, Uri}; use actix_http::http::{PathAndQuery, Uri};
use actix_service::{Service, Transform}; use actix_service::{Service, Transform};
use bytes::Bytes; use bytes::Bytes;
use futures::future::{ok, Ready}; use futures_util::future::{ok, Ready};
use regex::Regex; use regex::Regex;
use crate::service::{ServiceRequest, ServiceResponse}; use crate::service::{ServiceRequest, ServiceResponse};

View file

@ -5,7 +5,7 @@ use std::{fmt, net};
use actix_http::http::{HeaderMap, Method, Uri, Version}; use actix_http::http::{HeaderMap, Method, Uri, Version};
use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead}; use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead};
use actix_router::{Path, Url}; use actix_router::{Path, Url};
use futures::future::{ok, Ready}; use futures_util::future::{ok, Ready};
use tinyvec::TinyVec; use tinyvec::TinyVec;
use crate::config::AppConfig; use crate::config::AppConfig;

View file

@ -11,7 +11,7 @@ use actix_service::boxed::{self, BoxService, BoxServiceFactory};
use actix_service::{ use actix_service::{
apply, apply_fn_factory, IntoServiceFactory, Service, ServiceFactory, Transform, apply, apply_fn_factory, IntoServiceFactory, Service, ServiceFactory, Transform,
}; };
use futures::future::{ok, Either, LocalBoxFuture, Ready}; use futures_util::future::{ok, Either, LocalBoxFuture, Ready};
use crate::data::Data; use crate::data::Data;
use crate::dev::{insert_slash, AppService, HttpServiceFactory, ResourceDef}; use crate::dev::{insert_slash, AppService, HttpServiceFactory, ResourceDef};
@ -588,7 +588,7 @@ mod tests {
use actix_rt::time::delay_for; use actix_rt::time::delay_for;
use actix_service::Service; use actix_service::Service;
use futures::future::ok; use futures_util::future::ok;
use crate::http::{header, HeaderValue, Method, StatusCode}; use crate::http::{header, HeaderValue, Method, StatusCode};
use crate::middleware::DefaultHeaders; use crate::middleware::DefaultHeaders;

View file

@ -10,8 +10,8 @@ use actix_http::http::{
}; };
use actix_http::{Error, Response, ResponseBuilder}; use actix_http::{Error, Response, ResponseBuilder};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures::future::{err, ok, Either as EitherFuture, Ready}; use futures_util::future::{err, ok, Either as EitherFuture, Ready};
use futures::ready; use futures_util::ready;
use pin_project::{pin_project, project}; use pin_project::{pin_project, project};
use crate::request::HttpRequest; use crate::request::HttpRequest;

View file

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use actix_http::{http::Method, Error}; use actix_http::{http::Method, Error};
use actix_service::{Service, ServiceFactory}; use actix_service::{Service, ServiceFactory};
use futures::future::{ready, FutureExt, LocalBoxFuture}; use futures_util::future::{ready, FutureExt, LocalBoxFuture};
use crate::extract::FromRequest; use crate::extract::FromRequest;
use crate::guard::{self, Guard}; use crate::guard::{self, Guard};

View file

@ -1,5 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::rc::Rc; use std::rc::Rc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
@ -10,7 +11,7 @@ use actix_service::boxed::{self, BoxService, BoxServiceFactory};
use actix_service::{ use actix_service::{
apply, apply_fn_factory, IntoServiceFactory, Service, ServiceFactory, Transform, apply, apply_fn_factory, IntoServiceFactory, Service, ServiceFactory, Transform,
}; };
use futures::future::{ok, Either, Future, LocalBoxFuture, Ready}; use futures_util::future::{ok, Either, LocalBoxFuture, Ready};
use crate::config::ServiceConfig; use crate::config::ServiceConfig;
use crate::data::Data; use crate::data::Data;
@ -666,7 +667,7 @@ impl ServiceFactory for ScopeEndpoint {
mod tests { mod tests {
use actix_service::Service; use actix_service::Service;
use bytes::Bytes; use bytes::Bytes;
use futures::future::ok; use futures_util::future::ok;
use crate::dev::{Body, ResponseBody}; use crate::dev::{Body, ResponseBody};
use crate::http::{header, HeaderValue, Method, StatusCode}; use crate::http::{header, HeaderValue, Method, StatusCode};

View file

@ -13,7 +13,7 @@ use actix_http::Protocol;
#[cfg(unix)] #[cfg(unix)]
use actix_service::pipeline_factory; use actix_service::pipeline_factory;
#[cfg(unix)] #[cfg(unix)]
use futures::future::ok; use futures_util::future::ok;
#[cfg(feature = "openssl")] #[cfg(feature = "openssl")]
use actix_tls::openssl::{AlpnError, SslAcceptor, SslAcceptorBuilder}; use actix_tls::openssl::{AlpnError, SslAcceptor, SslAcceptorBuilder};

View file

@ -536,7 +536,7 @@ mod tests {
use crate::test::{init_service, TestRequest}; use crate::test::{init_service, TestRequest};
use crate::{guard, http, web, App, HttpResponse}; use crate::{guard, http, web, App, HttpResponse};
use actix_service::Service; use actix_service::Service;
use futures::future::ok; use futures_util::future::ok;
#[test] #[test]
fn test_service_request() { fn test_service_request() {

View file

@ -18,8 +18,9 @@ use actix_service::{
use awc::error::PayloadError; use awc::error::PayloadError;
use awc::{Client, ClientRequest, ClientResponse, Connector}; use awc::{Client, ClientRequest, ClientResponse, Connector};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures::future::ok; use futures_core::Stream;
use futures::stream::{Stream, StreamExt}; use futures_util::future::ok;
use futures_util::StreamExt;
use net2::TcpBuilder; use net2::TcpBuilder;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;

View file

@ -9,8 +9,8 @@ use std::{fmt, ops};
use actix_http::{Error, HttpMessage, Payload, Response}; use actix_http::{Error, HttpMessage, Payload, Response};
use bytes::BytesMut; use bytes::BytesMut;
use encoding_rs::{Encoding, UTF_8}; use encoding_rs::{Encoding, UTF_8};
use futures::future::{err, ok, FutureExt, LocalBoxFuture, Ready}; use futures_util::future::{err, ok, FutureExt, LocalBoxFuture, Ready};
use futures::StreamExt; use futures_util::StreamExt;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;

View file

@ -7,8 +7,8 @@ use std::task::{Context, Poll};
use std::{fmt, ops}; use std::{fmt, ops};
use bytes::BytesMut; use bytes::BytesMut;
use futures::future::{err, ok, FutureExt, LocalBoxFuture, Ready}; use futures_util::future::{err, ok, FutureExt, LocalBoxFuture, Ready};
use futures::StreamExt; use futures_util::StreamExt;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;

View file

@ -4,7 +4,7 @@ use std::{fmt, ops};
use actix_http::error::{Error, ErrorNotFound}; use actix_http::error::{Error, ErrorNotFound};
use actix_router::PathDeserializer; use actix_router::PathDeserializer;
use futures::future::{ready, Ready}; use futures_util::future::{ready, Ready};
use serde::de; use serde::de;
use crate::dev::Payload; use crate::dev::Payload;

View file

@ -8,8 +8,9 @@ use actix_http::error::{Error, ErrorBadRequest, PayloadError};
use actix_http::HttpMessage; use actix_http::HttpMessage;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use encoding_rs::UTF_8; use encoding_rs::UTF_8;
use futures::future::{err, ok, Either, FutureExt, LocalBoxFuture, Ready}; use futures_core::stream::Stream;
use futures::{Stream, StreamExt}; use futures_util::future::{err, ok, Either, FutureExt, LocalBoxFuture, Ready};
use futures_util::StreamExt;
use mime::Mime; use mime::Mime;
use crate::dev; use crate::dev;
@ -22,9 +23,10 @@ use crate::request::HttpRequest;
/// ## Example /// ## Example
/// ///
/// ```rust /// ```rust
/// use futures::{Future, Stream, StreamExt};
/// use actix_web::{web, error, App, Error, HttpResponse}; /// use actix_web::{web, error, App, Error, HttpResponse};
/// /// use std::future::Future;
/// use futures_core::stream::Stream;
/// use futures_util::StreamExt;
/// /// extract binary data from request /// /// extract binary data from request
/// async fn index(mut body: web::Payload) -> Result<HttpResponse, Error> /// async fn index(mut body: web::Payload) -> Result<HttpResponse, Error>
/// { /// {
@ -70,8 +72,10 @@ impl Stream for Payload {
/// ## Example /// ## Example
/// ///
/// ```rust /// ```rust
/// use futures::{Future, Stream, StreamExt};
/// use actix_web::{web, error, App, Error, HttpResponse}; /// use actix_web::{web, error, App, Error, HttpResponse};
/// use std::future::Future;
/// use futures_core::stream::Stream;
/// use futures_util::StreamExt;
/// ///
/// /// extract binary data from request /// /// extract binary data from request
/// async fn index(mut body: web::Payload) -> Result<HttpResponse, Error> /// async fn index(mut body: web::Payload) -> Result<HttpResponse, Error>

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use std::{fmt, ops}; use std::{fmt, ops};
use actix_http::error::Error; use actix_http::error::Error;
use futures::future::{err, ok, Ready}; use futures_util::future::{err, ok, Ready};
use serde::de; use serde::de;
use crate::dev::Payload; use crate::dev::Payload;

View file

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use encoding_rs::{Encoding, UTF_8}; use encoding_rs::{Encoding, UTF_8};
use futures::Stream; use futures_util::stream::Stream;
use crate::dev::Payload; use crate::dev::Payload;
use crate::error::{PayloadError, ReadlinesError}; use crate::error::{PayloadError, ReadlinesError};
@ -172,7 +172,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use futures::stream::StreamExt; use futures_util::stream::StreamExt;
use super::*; use super::*;
use crate::test::TestRequest; use crate::test::TestRequest;

View file

@ -1,11 +1,11 @@
//! Essentials helper functions and types for application registration. //! Essentials helper functions and types for application registration.
use actix_http::http::Method; use actix_http::http::Method;
use actix_router::IntoPattern; use actix_router::IntoPattern;
use futures::Future; use std::future::Future;
pub use actix_http::Response as HttpResponse; pub use actix_http::Response as HttpResponse;
pub use bytes::{Bytes, BytesMut}; pub use bytes::{Bytes, BytesMut};
pub use futures::channel::oneshot::Canceled; pub use futures_channel::oneshot::Canceled;
use crate::error::BlockingError; use crate::error::BlockingError;
use crate::extract::FromRequest; use crate::extract::FromRequest;

View file

@ -1,3 +1,4 @@
use std::future::Future;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
@ -11,7 +12,7 @@ use bytes::Bytes;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder}; use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder};
use flate2::Compression; use flate2::Compression;
use futures::{ready, Future}; use futures_util::ready;
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
use actix_web::dev::BodyEncoding; use actix_web::dev::BodyEncoding;
@ -56,7 +57,7 @@ impl TestBody {
} }
} }
impl futures::Stream for TestBody { impl futures_core::stream::Stream for TestBody {
type Item = Result<Bytes, Error>; type Item = Result<Bytes, Error>;
fn poll_next( fn poll_next(