From bc834f6a035a05b2a4f56b0fbde96e91621bf398 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 4 Apr 2019 10:59:34 -0700 Subject: [PATCH] remove some static contraints --- actix-http/Cargo.toml | 2 +- actix-http/src/builder.rs | 7 +++-- actix-http/src/client/connection.rs | 2 +- actix-http/src/h1/dispatcher.rs | 8 +++--- actix-http/src/h1/service.rs | 5 +--- actix-http/src/h2/dispatcher.rs | 34 ++++++++++++----------- actix-http/src/h2/service.rs | 33 ++++++++++++---------- actix-http/src/service/service.rs | 43 ++++++++++++++++------------- awc/Cargo.toml | 4 +-- awc/src/response.rs | 2 +- awc/src/ws.rs | 2 +- src/middleware/compress.rs | 10 +------ src/middleware/cors.rs | 8 ++---- src/middleware/identity.rs | 4 ++- test-server/Cargo.toml | 4 +-- 15 files changed, 84 insertions(+), 84 deletions(-) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 9d4e15216..0aa264e2e 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -51,7 +51,7 @@ secure-cookies = ["ring"] actix-service = "0.3.4" actix-codec = "0.1.2" actix-connect = "0.1.0" -actix-utils = "0.3.4" +actix-utils = "0.3.5" actix-server-config = "0.1.0" actix-threadpool = "0.1.0" diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index 2f7466a90..74ba1aed1 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use std::marker::PhantomData; use actix_server_config::ServerConfig as SrvConfig; -use actix_service::{IntoNewService, NewService}; +use actix_service::{IntoNewService, NewService, Service}; use crate::body::MessageBody; use crate::config::{KeepAlive, ServiceConfig}; @@ -27,8 +27,7 @@ pub struct HttpServiceBuilder { impl HttpServiceBuilder where S: NewService, - S::Error: Debug + 'static, - S::Service: 'static, + S::Error: Debug, { /// Create instance of `ServiceConfigBuilder` pub fn new() -> HttpServiceBuilder { @@ -115,6 +114,7 @@ where B: MessageBody + 'static, F: IntoNewService, S::Response: Into>, + ::Future: 'static, { let cfg = ServiceConfig::new( self.keep_alive, @@ -130,6 +130,7 @@ where B: MessageBody + 'static, F: IntoNewService, S::Response: Into>, + ::Future: 'static, { let cfg = ServiceConfig::new( self.keep_alive, diff --git a/actix-http/src/client/connection.rs b/actix-http/src/client/connection.rs index 4522dbbd3..c5d720efd 100644 --- a/actix-http/src/client/connection.rs +++ b/actix-http/src/client/connection.rs @@ -69,7 +69,7 @@ where } } -impl IoConnection { +impl IoConnection { pub(crate) fn new( io: ConnectionType, created: time::Instant, diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 96db08122..0f9b495b3 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -37,14 +37,14 @@ bitflags! { } /// Dispatcher for HTTP/1.1 protocol -pub struct Dispatcher + 'static, B: MessageBody> +pub struct Dispatcher, B: MessageBody> where S::Error: Debug, { inner: Option>, } -struct InnerDispatcher + 'static, B: MessageBody> +struct InnerDispatcher, B: MessageBody> where S::Error: Debug, { @@ -86,7 +86,7 @@ impl, B: MessageBody> State { impl Dispatcher where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, S::Response: Into>, B: MessageBody, @@ -144,7 +144,7 @@ where impl InnerDispatcher where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, S::Response: Into>, B: MessageBody, diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index f3301b9b2..d7ab50626 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -30,7 +30,6 @@ where S: NewService, S::Error: Debug, S::Response: Into>, - S::Service: 'static, B: MessageBody, { /// Create new `HttpService` instance with default config. @@ -63,7 +62,6 @@ where S: NewService, S::Error: Debug, S::Response: Into>, - S::Service: 'static, B: MessageBody, { type Request = Io; @@ -93,7 +91,6 @@ impl Future for H1ServiceResponse where T: AsyncRead + AsyncWrite, S: NewService, - S::Service: 'static, S::Error: Debug, S::Response: Into>, B: MessageBody, @@ -111,7 +108,7 @@ where } /// `Service` implementation for HTTP1 transport -pub struct H1ServiceHandler { +pub struct H1ServiceHandler { srv: CloneableService, cfg: ServiceConfig, _t: PhantomData<(T, P, B)>, diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 9b43be669..0ef40fc08 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -31,7 +31,7 @@ const CHUNK_SIZE: usize = 16_384; /// Dispatcher for HTTP/2 protocol pub struct Dispatcher< T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, B: MessageBody, > { service: CloneableService, @@ -45,8 +45,9 @@ pub struct Dispatcher< impl Dispatcher where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: fmt::Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -86,8 +87,9 @@ where impl Future for Dispatcher where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: fmt::Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -115,7 +117,7 @@ where head.method = parts.method; head.version = parts.version; head.headers = parts.headers; - tokio_current_thread::spawn(ServiceResponse:: { + tokio_current_thread::spawn(ServiceResponse:: { state: ServiceResponseState::ServiceCall( self.service.call(req), Some(res), @@ -130,22 +132,22 @@ where } } -struct ServiceResponse { - state: ServiceResponseState, +struct ServiceResponse { + state: ServiceResponseState, config: ServiceConfig, buffer: Option, } -enum ServiceResponseState { - ServiceCall(S::Future, Option>), +enum ServiceResponseState { + ServiceCall(F, Option>), SendPayload(SendStream, ResponseBody), } -impl ServiceResponse +impl ServiceResponse where - S: Service + 'static, - S::Error: fmt::Debug, - S::Response: Into>, + F: Future, + F::Error: fmt::Debug, + F::Item: Into>, B: MessageBody + 'static, { fn prepare_response( @@ -209,11 +211,11 @@ where } } -impl Future for ServiceResponse +impl Future for ServiceResponse where - S: Service + 'static, - S::Error: fmt::Debug, - S::Response: Into>, + F: Future, + F::Error: fmt::Debug, + F::Item: Into>, B: MessageBody + 'static, { type Item = (); diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index 9d9a19e24..16ccd79a5 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -32,9 +32,9 @@ pub struct H2Service { impl H2Service where S: NewService, - S::Service: 'static, - S::Error: Debug + 'static, + S::Error: Debug, S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { /// Create new `HttpService` instance. @@ -65,9 +65,9 @@ impl NewService for H2Service where T: AsyncRead + AsyncWrite, S: NewService, - S::Service: 'static, S::Error: Debug, S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { type Request = Io; @@ -97,9 +97,9 @@ impl Future for H2ServiceResponse where T: AsyncRead + AsyncWrite, S: NewService, - S::Service: 'static, - S::Response: Into>, S::Error: Debug, + S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { type Item = H2ServiceHandler; @@ -115,7 +115,7 @@ where } /// `Service` implementation for http/2 transport -pub struct H2ServiceHandler { +pub struct H2ServiceHandler { srv: CloneableService, cfg: ServiceConfig, _t: PhantomData<(T, P, B)>, @@ -123,8 +123,9 @@ pub struct H2ServiceHandler { impl H2ServiceHandler where - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -140,8 +141,9 @@ where impl Service for H2ServiceHandler where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -168,11 +170,10 @@ where } } -enum State< - T: AsyncRead + AsyncWrite, - S: Service + 'static, - B: MessageBody, -> { +enum State, B: MessageBody> +where + S::Future: 'static, +{ Incoming(Dispatcher), Handshake( Option>, @@ -184,8 +185,9 @@ enum State< pub struct H2ServiceHandlerResponse where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -195,8 +197,9 @@ where impl Future for H2ServiceHandlerResponse where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody, { diff --git a/actix-http/src/service/service.rs b/actix-http/src/service/service.rs index 50a1a6bdf..f97cc0483 100644 --- a/actix-http/src/service/service.rs +++ b/actix-http/src/service/service.rs @@ -29,9 +29,9 @@ pub struct HttpService { impl HttpService where S: NewService, - S::Service: 'static, - S::Error: Debug + 'static, + S::Error: Debug, S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { /// Create builder for `HttpService` instance. @@ -43,9 +43,9 @@ where impl HttpService where S: NewService, - S::Service: 'static, - S::Error: Debug + 'static, + S::Error: Debug, S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { /// Create new `HttpService` instance. @@ -74,11 +74,11 @@ where impl NewService for HttpService where - T: AsyncRead + AsyncWrite + 'static, + T: AsyncRead + AsyncWrite, S: NewService, - S::Service: 'static, S::Error: Debug, S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { type Request = ServerIo; @@ -108,9 +108,9 @@ impl Future for HttpServiceResponse where T: AsyncRead + AsyncWrite, S: NewService, - S::Service: 'static, - S::Response: Into>, S::Error: Debug, + S::Response: Into>, + ::Future: 'static, B: MessageBody + 'static, { type Item = HttpServiceHandler; @@ -126,7 +126,7 @@ where } /// `Service` implementation for http transport -pub struct HttpServiceHandler { +pub struct HttpServiceHandler { srv: CloneableService, cfg: ServiceConfig, _t: PhantomData<(T, P, B)>, @@ -134,8 +134,9 @@ pub struct HttpServiceHandler { impl HttpServiceHandler where - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -150,9 +151,10 @@ where impl Service for HttpServiceHandler where - T: AsyncRead + AsyncWrite + 'static, - S: Service + 'static, + T: AsyncRead + AsyncWrite, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -203,10 +205,11 @@ where } } -enum State + 'static, B: MessageBody> +enum State, B: MessageBody> where + S::Future: 'static, S::Error: fmt::Debug, - T: AsyncRead + AsyncWrite + 'static, + T: AsyncRead + AsyncWrite, { H1(h1::Dispatcher), H2(Dispatcher, S, B>), @@ -216,9 +219,10 @@ where pub struct HttpServiceHandlerResponse where - T: AsyncRead + AsyncWrite + 'static, - S: Service + 'static, + T: AsyncRead + AsyncWrite, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody + 'static, { @@ -230,8 +234,9 @@ const HTTP2_PREFACE: [u8; 14] = *b"PRI * HTTP/2.0"; impl Future for HttpServiceHandlerResponse where T: AsyncRead + AsyncWrite, - S: Service + 'static, + S: Service, S::Error: Debug, + S::Future: 'static, S::Response: Into>, B: MessageBody, { @@ -331,13 +336,13 @@ impl io::Write for Io { } } -impl AsyncRead for Io { +impl AsyncRead for Io { unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool { self.inner.prepare_uninitialized_buffer(buf) } } -impl AsyncWrite for Io { +impl AsyncWrite for Io { fn shutdown(&mut self) -> Poll<(), io::Error> { self.inner.shutdown() } diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 81d91e19f..9f4d916e4 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -38,7 +38,7 @@ flate2-rust = ["actix-http/flate2-rust"] [dependencies] actix-codec = "0.1.1" actix-service = "0.3.4" -actix-http = "0.1.0-alpa.3" +actix-http = "0.1.0-alpha.3" base64 = "0.10.1" bytes = "0.4" derive_more = "0.14" @@ -56,7 +56,7 @@ openssl = { version="0.10", optional = true } [dev-dependencies] actix-rt = "0.2.2" actix-web = { version = "1.0.0-alpha.3", features=["ssl"] } -actix-http = { version = "0.1.0-alpa.3", features=["ssl"] } +actix-http = { version = "0.1.0-alpha.3", features=["ssl"] } actix-http-test = { version = "0.1.0-alpha.3", features=["ssl"] } actix-utils = "0.3.4" actix-server = { version = "0.4.1", features=["ssl"] } diff --git a/awc/src/response.rs b/awc/src/response.rs index 73194d673..b6d7bba65 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -282,7 +282,7 @@ where impl Future for JsonBody where T: Stream, - U: DeserializeOwned + 'static, + U: DeserializeOwned, { type Item = U; type Error = JsonPayloadError; diff --git a/awc/src/ws.rs b/awc/src/ws.rs index bbeaa061b..a28518983 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -70,7 +70,7 @@ impl WebsocketsRequest { /// Set supported websocket protocols pub fn protocols(mut self, protos: U) -> Self where - U: IntoIterator + 'static, + U: IntoIterator, V: AsRef, { let mut protos = protos diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs index f74754402..ed3943711 100644 --- a/src/middleware/compress.rs +++ b/src/middleware/compress.rs @@ -70,10 +70,8 @@ impl Default for Compress { impl Transform for Compress where - P: 'static, B: MessageBody, S: Service, Response = ServiceResponse>, - S::Future: 'static, { type Request = ServiceRequest

; type Response = ServiceResponse>; @@ -97,10 +95,8 @@ pub struct CompressMiddleware { impl Service for CompressMiddleware where - P: 'static, B: MessageBody, S: Service, Response = ServiceResponse>, - S::Future: 'static, { type Request = ServiceRequest

; type Response = ServiceResponse>; @@ -134,10 +130,8 @@ where #[doc(hidden)] pub struct CompressResponse where - P: 'static, - B: MessageBody, S: Service, - S::Future: 'static, + B: MessageBody, { fut: S::Future, encoding: ContentEncoding, @@ -146,10 +140,8 @@ where impl Future for CompressResponse where - P: 'static, B: MessageBody, S: Service, Response = ServiceResponse>, - S::Future: 'static, { type Item = ServiceResponse>; type Error = S::Error; diff --git a/src/middleware/cors.rs b/src/middleware/cors.rs index 920b480bb..f003ac95b 100644 --- a/src/middleware/cors.rs +++ b/src/middleware/cors.rs @@ -477,8 +477,9 @@ fn cors<'a>( impl IntoTransform for Cors where - S: Service, Response = ServiceResponse> + 'static, - P: 'static, + S: Service, Response = ServiceResponse>, + S::Future: 'static, + S::Error: 'static, B: 'static, { fn into_transform(self) -> CorsFactory { @@ -541,7 +542,6 @@ where S: Service, Response = ServiceResponse>, S::Future: 'static, S::Error: 'static, - P: 'static, B: 'static, { type Request = ServiceRequest

; @@ -683,7 +683,6 @@ where S: Service, Response = ServiceResponse>, S::Future: 'static, S::Error: 'static, - P: 'static, B: 'static, { type Request = ServiceRequest

; @@ -826,7 +825,6 @@ mod tests { + 'static, S::Future: 'static, S::Error: 'static, - P: 'static, B: 'static, { block_on( diff --git a/src/middleware/identity.rs b/src/middleware/identity.rs index 7a2c9f376..3df2f0e3b 100644 --- a/src/middleware/identity.rs +++ b/src/middleware/identity.rs @@ -202,10 +202,11 @@ impl IdentityService { impl Transform for IdentityService where - P: 'static, S: Service, Response = ServiceResponse> + 'static, S::Future: 'static, + S::Error: 'static, T: IdentityPolicy, + P: 'static, B: 'static, { type Request = ServiceRequest

; @@ -235,6 +236,7 @@ where B: 'static, S: Service, Response = ServiceResponse> + 'static, S::Future: 'static, + S::Error: 'static, T: IdentityPolicy, { type Request = ServiceRequest

; diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index f85e2b156..fefcb5184 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -55,5 +55,5 @@ tokio-timer = "0.2" openssl = { version="0.10", optional = true } [dev-dependencies] -actix-web = "1.0.0-alpa.3" -actix-http = "0.1.0-alpa.3" +actix-web = "1.0.0-alpha.3" +actix-http = "0.1.0-alpha.3"