From 3dd8635ee46583706b5ad597fedcc9ffb9f37b23 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 1 Dec 2021 00:17:45 +0000 Subject: [PATCH] remove redundant messagebody bounds --- CHANGES.md | 4 ++-- actix-http/CHANGES.md | 18 ++++++++---------- actix-http/src/body/body.rs | 3 --- actix-http/src/body/boxed.rs | 1 - actix-http/src/body/either.rs | 3 --- actix-http/src/builder.rs | 4 +--- actix-http/src/h1/dispatcher.rs | 9 --------- actix-http/src/h1/service.rs | 6 ------ actix-http/src/h2/dispatcher.rs | 2 -- actix-http/src/h2/service.rs | 8 -------- actix-http/src/response.rs | 2 -- actix-http/src/response_builder.rs | 2 -- actix-http/src/service.rs | 10 ---------- actix-test/src/lib.rs | 4 +--- benches/responder.rs | 17 +++++++++++------ src/middleware/compat.rs | 2 -- src/response/builder.rs | 1 - src/response/response.rs | 2 -- src/server.rs | 8 ++------ src/service.rs | 2 -- src/types/either.rs | 4 +--- 21 files changed, 26 insertions(+), 86 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 514299e45..8f1f06248 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ ### Added * Methods on `AcceptLanguage`: `ranked` and `preference`. [#2480] * `AcceptEncoding` typed header. [#2482] -* `HttpResponse::map_into_boxed_body`. [#????] +* `HttpResponse::map_into_boxed_body`. [#2468] ### Changed * Rename `Accept::{mime_precedence => ranked}`. [#2480] @@ -14,7 +14,7 @@ * Accept wildcard `*` items in `AcceptLanguage`. [#2480] * Typed headers containing lists that require one or more items now enforce this minimum. [#2482] -[#????]: https://github.com/actix/actix-web/pull/???? +[#2468]: https://github.com/actix/actix-web/pull/2468 [#2480]: https://github.com/actix/actix-web/pull/2480 [#2482]: https://github.com/actix/actix-web/pull/2482 diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index a4ede553a..be9775e77 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -4,22 +4,20 @@ ### Added * Add timeout for canceling HTTP/2 server side connection handshake. Default to 5 seconds. [#2483] * HTTP/2 handshake timeout can be configured with `ServiceConfig::client_timeout`. [#2483] -* Rename `body::BoxBody::{from_body => new}`. [#????] -* `Response::into_boxed_body`. [#????] -* `Response::map_into_boxed_body`. [#????] -* `body::EitherBody` enum. [#????] -* `body::None` struct. [#????] -* `impl Clone for ws::HandshakeError`. [#????] +* `Response::map_into_boxed_body`. [#2468] +* `body::EitherBody` enum. [#2468] +* `body::None` struct. [#2468] +* `impl Clone for ws::HandshakeError`. [#2468] ### Changed -* Rename `body::BoxBody::{from_body => new}`. [#????] -* Body type for `Responses` returned from `Response::{new, ok, etc...}` is now `BoxBody`. [#????] +* Rename `body::BoxBody::{from_body => new}`. [#2468] +* Body type for `Responses` returned from `Response::{new, ok, etc...}` is now `BoxBody`. [#2468] ### Removed -* Remove unnecessary `MessageBody` bound on types passed to `body::AnyBody::new`. [#????] +* Remove unnecessary `MessageBody` bound on types passed to `body::AnyBody::new`. [#2468] [#2483]: https://github.com/actix/actix-web/pull/2483 -[#????]: https://github.com/actix/actix-web/pull/???? +[#2468]: https://github.com/actix/actix-web/pull/2468 ## 3.0.0-beta.14 - 2021-11-30 diff --git a/actix-http/src/body/body.rs b/actix-http/src/body/body.rs index c705ba3b2..0dada52ae 100644 --- a/actix-http/src/body/body.rs +++ b/actix-http/src/body/body.rs @@ -48,7 +48,6 @@ impl AnyBody { pub fn new_boxed(body: B) -> Self where B: MessageBody + 'static, - B::Error: Into>, { Self::Body { body: BoxBody::new(body), @@ -83,7 +82,6 @@ impl AnyBody { impl AnyBody where B: MessageBody + 'static, - B::Error: Into>, { pub fn into_boxed(self) -> AnyBody { match self { @@ -97,7 +95,6 @@ where impl MessageBody for AnyBody where B: MessageBody, - B::Error: Into> + 'static, { type Error = Error; diff --git a/actix-http/src/body/boxed.rs b/actix-http/src/body/boxed.rs index 249b5bbb2..9442bd1df 100644 --- a/actix-http/src/body/boxed.rs +++ b/actix-http/src/body/boxed.rs @@ -18,7 +18,6 @@ impl BoxBody { pub fn new(body: B) -> Self where B: MessageBody + 'static, - B::Error: Into>, { let body = MessageBodyMapErr::new(body, Into::into); Self(Box::pin(body)) diff --git a/actix-http/src/body/either.rs b/actix-http/src/body/either.rs index 38f164762..6169ee627 100644 --- a/actix-http/src/body/either.rs +++ b/actix-http/src/body/either.rs @@ -1,5 +1,4 @@ use std::{ - error::Error as StdError, pin::Pin, task::{Context, Poll}, }; @@ -44,9 +43,7 @@ impl EitherBody { impl MessageBody for EitherBody where L: MessageBody + 'static, - L::Error: Into>, R: MessageBody + 'static, - R::Error: Into>, { type Error = Error; diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index e9af3809c..ca821f1d9 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -1,4 +1,4 @@ -use std::{error::Error as StdError, fmt, marker::PhantomData, net, rc::Rc}; +use std::{fmt, marker::PhantomData, net, rc::Rc}; use actix_codec::Framed; use actix_service::{IntoServiceFactory, Service, ServiceFactory}; @@ -205,7 +205,6 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, { let cfg = ServiceConfig::new( self.keep_alive, @@ -228,7 +227,6 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, { let cfg = ServiceConfig::new( self.keep_alive, diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index b8b30df33..ebd22f48b 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -1,6 +1,5 @@ use std::{ collections::VecDeque, - error::Error as StdError, fmt, future::Future, io, mem, net, @@ -54,7 +53,6 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -76,7 +74,6 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -95,7 +92,6 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -137,7 +133,6 @@ where X: Service, B: MessageBody, - B::Error: Into>, { None, ExpectCall(#[pin] X::Future), @@ -153,7 +148,6 @@ where X: Service, B: MessageBody, - B::Error: Into>, { fn is_empty(&self) -> bool { matches!(self, State::None) @@ -175,7 +169,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -236,7 +229,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -913,7 +905,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index 2baf05c94..70e83901c 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -1,5 +1,4 @@ use std::{ - error::Error as StdError, fmt, marker::PhantomData, net, @@ -68,7 +67,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -119,7 +117,6 @@ mod openssl { S::Response: Into>, B: MessageBody, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -182,7 +179,6 @@ mod rustls { S::Response: Into>, B: MessageBody, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -282,7 +278,6 @@ where S::InitError: fmt::Debug, B: MessageBody, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -351,7 +346,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 322919873..6d2f4579a 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -97,7 +97,6 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, { type Output = Result<(), crate::error::DispatchError>; @@ -207,7 +206,6 @@ async fn handle_response( ) -> Result<(), DispatchError> where B: MessageBody, - B::Error: Into>, { let (res, body) = res.replace_body(()); diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index 872606f63..8a9061b94 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -1,5 +1,4 @@ use std::{ - error::Error as StdError, future::Future, marker::PhantomData, net, @@ -44,7 +43,6 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { /// Create new `H2Service` instance with config. pub(crate) fn with_config>( @@ -75,7 +73,6 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { /// Create plain TCP based service pub fn tcp( @@ -119,7 +116,6 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { /// Create OpenSSL based service. pub fn openssl( @@ -167,7 +163,6 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { /// Create Rustls based service. pub fn rustls( @@ -209,7 +204,6 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { type Response = (); type Error = DispatchError; @@ -271,7 +265,6 @@ where S::Future: 'static, S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, { type Response = (); type Error = DispatchError; @@ -336,7 +329,6 @@ where S::Future: 'static, S::Response: Into> + 'static, B: MessageBody, - B::Error: Into>, { type Output = Result<(), DispatchError>; diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 79d354a1a..282118b21 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -2,7 +2,6 @@ use std::{ cell::{Ref, RefMut}, - error::Error as StdError, fmt, str, }; @@ -194,7 +193,6 @@ impl Response { pub fn map_into_boxed_body(self) -> Response where B: MessageBody + 'static, - B::Error: Into>, { self.map_body(|_, body| BoxBody::new(body)) } diff --git a/actix-http/src/response_builder.rs b/actix-http/src/response_builder.rs index dae204000..2a4317871 100644 --- a/actix-http/src/response_builder.rs +++ b/actix-http/src/response_builder.rs @@ -2,7 +2,6 @@ use std::{ cell::{Ref, RefMut}, - error::Error as StdError, fmt, future::Future, pin::Pin, @@ -235,7 +234,6 @@ impl ResponseBuilder { pub fn body(&mut self, body: B) -> Response> where B: MessageBody + 'static, - B::Error: Into>, { match self.message_body(body) { Ok(res) => res.map_body(|_, body| EitherBody::left(body)), diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 2e2d44ba9..7af34ba05 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -1,5 +1,4 @@ use std::{ - error::Error as StdError, fmt, future::Future, marker::PhantomData, @@ -58,7 +57,6 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { /// Create new `HttpService` instance. pub fn new>(service: F) -> Self { @@ -157,7 +155,6 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -214,7 +211,6 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -287,7 +283,6 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -354,7 +349,6 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -491,7 +485,6 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, X: Service, X::Error: Into>, @@ -560,7 +553,6 @@ pin_project! { S::Error: Into>, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -597,7 +589,6 @@ pin_project! { S::Response: 'static, B: MessageBody, - B::Error: Into>, X: Service, X::Error: Into>, @@ -620,7 +611,6 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-test/src/lib.rs b/actix-test/src/lib.rs index b80918ec0..bc557441b 100644 --- a/actix-test/src/lib.rs +++ b/actix-test/src/lib.rs @@ -31,7 +31,7 @@ extern crate tls_openssl as openssl; #[cfg(feature = "rustls")] extern crate tls_rustls as rustls; -use std::{error::Error as StdError, fmt, net, thread, time::Duration}; +use std::{fmt, net, thread, time::Duration}; use actix_codec::{AsyncRead, AsyncWrite, Framed}; pub use actix_http::test::TestBuffer; @@ -88,7 +88,6 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { start_with(TestServerConfig::default(), factory) } @@ -128,7 +127,6 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, { // for sending handles and server info back from the spawned thread let (started_tx, started_rx) = std::sync::mpsc::channel(); diff --git a/benches/responder.rs b/benches/responder.rs index 5d0b98d5f..20aae3351 100644 --- a/benches/responder.rs +++ b/benches/responder.rs @@ -1,9 +1,10 @@ use std::{future::Future, time::Instant}; +use actix_http::body::BoxBody; use actix_utils::future::{ready, Ready}; -use actix_web::http::StatusCode; -use actix_web::test::TestRequest; -use actix_web::{error, Error, HttpRequest, HttpResponse, Responder}; +use actix_web::{ + error, http::StatusCode, test::TestRequest, Error, HttpRequest, HttpResponse, Responder, +}; use criterion::{criterion_group, criterion_main, Criterion}; use futures_util::future::{join_all, Either}; @@ -50,7 +51,9 @@ where } impl Responder for StringResponder { - fn respond_to(self, _: &HttpRequest) -> HttpResponse { + type Body = BoxBody; + + fn respond_to(self, _: &HttpRequest) -> HttpResponse { HttpResponse::build(StatusCode::OK) .content_type("text/plain; charset=utf-8") .body(self.0) @@ -58,9 +61,11 @@ impl Responder for StringResponder { } impl Responder for OptionResponder { - fn respond_to(self, req: &HttpRequest) -> HttpResponse { + type Body = BoxBody; + + fn respond_to(self, req: &HttpRequest) -> HttpResponse { match self.0 { - Some(t) => t.respond_to(req), + Some(t) => t.respond_to(req).map_into_boxed_body(), None => HttpResponse::from_error(error::ErrorInternalServerError("err")), } } diff --git a/src/middleware/compat.rs b/src/middleware/compat.rs index d6dcd6d14..e6ef1806f 100644 --- a/src/middleware/compat.rs +++ b/src/middleware/compat.rs @@ -1,7 +1,6 @@ //! For middleware documentation, see [`Compat`]. use std::{ - error::Error as StdError, future::Future, pin::Pin, task::{Context, Poll}, @@ -123,7 +122,6 @@ pub trait MapServiceResponseBody { impl MapServiceResponseBody for ServiceResponse where B: MessageBody + Unpin + 'static, - B::Error: Into>, { fn map_body(self) -> ServiceResponse { self.map_into_boxed_body() diff --git a/src/response/builder.rs b/src/response/builder.rs index db493b69f..c7e7855c4 100644 --- a/src/response/builder.rs +++ b/src/response/builder.rs @@ -312,7 +312,6 @@ impl HttpResponseBuilder { pub fn body(&mut self, body: B) -> HttpResponse where B: MessageBody + 'static, - B::Error: Into>, { match self.message_body(body) { Ok(res) => res.map_into_boxed_body(), diff --git a/src/response/response.rs b/src/response/response.rs index 73964d732..376db3fa9 100644 --- a/src/response/response.rs +++ b/src/response/response.rs @@ -1,6 +1,5 @@ use std::{ cell::{Ref, RefMut}, - error::Error as StdError, fmt, future::Future, mem, @@ -241,7 +240,6 @@ impl HttpResponse { pub fn map_into_boxed_body(self) -> HttpResponse where B: MessageBody + 'static, - B::Error: Into>, { self.map_body(|_, body| BoxBody::new(body)) } diff --git a/src/server.rs b/src/server.rs index 2510dbba2..3db849410 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,8 +1,6 @@ use std::{ any::Any, - cmp, - error::Error as StdError, - fmt, io, + cmp, fmt, io, marker::PhantomData, net, sync::{Arc, Mutex}, @@ -75,15 +73,13 @@ where I: IntoServiceFactory, S: ServiceFactory + 'static, - // S::Future: 'static, S::Error: Into + 'static, S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, S::Service: 'static, - // S::Service: 'static, + B: MessageBody + 'static, - B::Error: Into>, { /// Create new HTTP server with application factory pub fn new(factory: F) -> Self { diff --git a/src/service.rs b/src/service.rs index 4d8d2b4b9..2c6acb182 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1,6 +1,5 @@ use std::{ cell::{Ref, RefMut}, - error::Error as StdError, fmt, net, rc::Rc, }; @@ -426,7 +425,6 @@ impl ServiceResponse { pub fn map_into_boxed_body(self) -> ServiceResponse where B: MessageBody + 'static, - B::Error: Into>, { self.map_body(|_, body| BoxBody::new(body)) } diff --git a/src/types/either.rs b/src/types/either.rs index 3ed55b248..3c759736e 100644 --- a/src/types/either.rs +++ b/src/types/either.rs @@ -14,7 +14,7 @@ use pin_project_lite::pin_project; use crate::{ body, dev, web::{Form, Json}, - BoxError, Error, FromRequest, HttpRequest, HttpResponse, Responder, + Error, FromRequest, HttpRequest, HttpResponse, Responder, }; /// Combines two extractor or responder types into a single type. @@ -144,9 +144,7 @@ impl Either { impl Responder for Either where L: Responder, - ::Error: Into, R: Responder, - ::Error: Into, { type Body = body::EitherBody;