use actix_http::Error; use actix_service::{NewService, Service}; use futures::{Future, Poll}; pub(crate) type BoxedHttpService = Box< Service< Request = Req, Response = (), Error = Error, Future = Box>, >, >; pub(crate) type BoxedHttpNewService = Box< NewService< Request = Req, Response = (), Error = Error, InitError = (), Service = BoxedHttpService, Future = Box, Error = ()>>, >, >; pub(crate) struct HttpNewService(T); impl HttpNewService where T: NewService, T::Response: 'static, T::Future: 'static, T::Service: Service>> + 'static, ::Future: 'static, { pub fn new(service: T) -> Self { HttpNewService(service) } } impl NewService for HttpNewService where T: NewService, T::Request: 'static, T::Future: 'static, T::Service: Service>> + 'static, ::Future: 'static, { type Request = T::Request; type Response = (); type Error = Error; type InitError = (); type Service = BoxedHttpService; type Future = Box>; fn new_service(&self, _: &()) -> Self::Future { Box::new(self.0.new_service(&()).map_err(|_| ()).and_then(|service| { let service: BoxedHttpService<_> = Box::new(HttpServiceWrapper { service }); Ok(service) })) } } struct HttpServiceWrapper { service: T, } impl Service for HttpServiceWrapper where T: Service< Response = (), Future = Box>, Error = Error, >, T::Request: 'static, { type Request = T::Request; type Response = (); type Error = Error; type Future = Box>; fn poll_ready(&mut self) -> Poll<(), Self::Error> { self.service.poll_ready() } fn call(&mut self, req: Self::Request) -> Self::Future { self.service.call(req) } }