From 4b098d31ae39b7978a057ffbbdc20ab247fd599c Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Tue, 29 Mar 2022 20:25:44 +0300 Subject: [PATCH] remove B generic --- actix-web/src/server.rs | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/actix-web/src/server.rs b/actix-web/src/server.rs index 77275ebf1..5edb0e7c3 100644 --- a/actix-web/src/server.rs +++ b/actix-web/src/server.rs @@ -2,9 +2,7 @@ use std::{ any::Any, cmp, fmt, future::Future, - io, - marker::PhantomData, - net, + io, net, sync::{Arc, Mutex}, time::Duration, }; @@ -23,7 +21,7 @@ use actix_tls::accept::openssl::reexports::{AlpnError, SslAcceptor, SslAcceptorB #[cfg(feature = "rustls")] use actix_tls::accept::rustls::reexports::ServerConfig as RustlsServerConfig; -use crate::{config::AppConfig, Error, HttpResponse}; +use crate::{config::AppConfig, Error}; struct Socket { scheme: &'static str, @@ -54,7 +52,7 @@ struct Config { /// .await /// } /// ``` -pub struct HttpServer { +pub struct HttpServer { pub(super) factory: SF, config: Arc>, backlog: u32, @@ -62,10 +60,9 @@ pub struct HttpServer { builder: ServerBuilder, #[allow(clippy::type_complexity)] on_connect_fn: Option>, - _phantom: PhantomData<(B,)>, } -impl HttpServer { +impl HttpServer<()> { /// Create new HTTP server with application factory pub fn new( factory_fn: F, @@ -73,12 +70,11 @@ impl HttpServer { impl ServiceFactory< Request, Config = AppConfig, - Error = HttpResponse, + Error = Response, InitError = SF::InitError, - Response = SF::Response, + Response = Response, > + Send + Clone, - B, > where F: FnOnce() -> I + Send + Clone + 'static, @@ -93,7 +89,8 @@ impl HttpServer { let factory_fn = factory_fn.clone(); async move { factory_fn().into_factory().new_service(cfg).await } }) - .map_err(|err| err.into().error_response()); + .map(|resp| resp.into()) + .map_err(|err| err.into().error_response().into()); HttpServer::new2(factory) } @@ -104,12 +101,11 @@ impl HttpServer { impl ServiceFactory< Request, Config = AppConfig, - Error = HttpResponse, + Error = Response, InitError = SF::InitError, - Response = SF::Response, + Response = Response, > + Send + Clone, - B, > where F: FnOnce() -> Fut + Send + Clone + 'static, @@ -125,18 +121,24 @@ impl HttpServer { let factory_fn = factory_fn.clone(); async move { factory_fn().await.into_factory().new_service(cfg).await } }) - .map_err(|err| err.into().error_response()); + .map(|resp| resp.into()) + .map_err(|err| err.into().error_response().into()); HttpServer::new2(factory) } } -impl HttpServer +impl HttpServer where - SF: ServiceFactory + Send + Clone + 'static, - SF::Error: Into>, + SF: ServiceFactory< + Request, + Config = AppConfig, + Response = Response, + Error = Response, + > + Send + + Clone + + 'static, SF::InitError: fmt::Debug, - SF::Response: Into>, B: MessageBody + 'static, { fn new2(factory: SF) -> Self { @@ -152,7 +154,6 @@ where sockets: Vec::new(), builder: ServerBuilder::default(), on_connect_fn: None, - _phantom: PhantomData, } } @@ -177,7 +178,6 @@ where sockets: self.sockets, builder: self.builder, on_connect_fn: Some(Arc::new(f)), - _phantom: PhantomData, } }