add changelog entry

This commit is contained in:
Rob Ede 2020-12-27 02:15:25 +00:00
parent f5808c6c40
commit 7de866dab3
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
10 changed files with 192 additions and 180 deletions

View File

@ -1,8 +1,14 @@
# Changes # Changes
## Unreleased - 2020-xx-xx ## Unreleased - 2020-xx-xx
* `Service`, other traits, and many type signatures now take the the request type as a type
parameter instead of an associated type. [#232]
* Upgrade `pin-project` to `1.0`. * Upgrade `pin-project` to `1.0`.
[#232]: https://github.com/actix/actix-net/pull/232
## 1.0.6 - 2020-08-09 ## 1.0.6 - 2020-08-09
### Fixed ### Fixed

View File

@ -12,12 +12,12 @@ use super::{IntoService, IntoServiceFactory, Service, ServiceFactory};
/// Apply transform function to a service. /// Apply transform function to a service.
/// ///
/// The In and Out type params refer to the request and response types for the wrapped service. /// The In and Out type params refer to the request and response types for the wrapped service.
pub fn apply_fn<U, S, F, Fut, Req, In, Res, Err>( pub fn apply_fn<I, S, F, Fut, Req, In, Res, Err>(
service: U, service: I,
wrap_fn: F, wrap_fn: F,
) -> Apply<S, F, Req, In, Res, Err> ) -> Apply<S, F, Req, In, Res, Err>
where where
U: IntoService<S, In>, I: IntoService<S, In>,
S: Service<In, Error = Err>, S: Service<In, Error = Err>,
F: FnMut(Req, &mut S) -> Fut, F: FnMut(Req, &mut S) -> Fut,
Fut: Future<Output = Result<Res, Err>>, Fut: Future<Output = Result<Res, Err>>,
@ -28,12 +28,12 @@ where
/// Service factory that produces `apply_fn` service. /// Service factory that produces `apply_fn` service.
/// ///
/// The In and Out type params refer to the request and response types for the wrapped service. /// The In and Out type params refer to the request and response types for the wrapped service.
pub fn apply_fn_factory<U, SF, F, Fut, Req, In, Res, Err>( pub fn apply_fn_factory<I, SF, F, Fut, Req, In, Res, Err>(
service: U, service: I,
f: F, f: F,
) -> ApplyFactory<SF, F, Req, In, Res, Err> ) -> ApplyFactory<SF, F, Req, In, Res, Err>
where where
U: IntoServiceFactory<SF, In>, I: IntoServiceFactory<SF, In>,
SF: ServiceFactory<In, Error = Err>, SF: ServiceFactory<In, Error = Err>,
F: FnMut(Req, &mut SF::Service) -> Fut + Clone, F: FnMut(Req, &mut SF::Service) -> Fut + Clone,
Fut: Future<Output = Result<Res, Err>>, Fut: Future<Output = Result<Res, Err>>,

View File

@ -7,150 +7,152 @@ use std::task::{Context, Poll};
use crate::{Service, ServiceFactory}; use crate::{Service, ServiceFactory};
/// Convert `Fn(Config, &mut Service1) -> Future<Service2>` fn to a service factory /// Convert `Fn(Config, &mut Service1) -> Future<Service2>` fn to a service factory.
pub fn apply_cfg<F, C, T, Req, R, S, E>( pub fn apply_cfg<S1, Req, F, Cfg, Fut, S2, Err>(
srv: T, srv: S1,
f: F, f: F,
) -> impl ServiceFactory< ) -> impl ServiceFactory<
Req, Req,
Config = C, Config = Cfg,
Response = S::Response, Response = S2::Response,
Error = S::Error, Error = S2::Error,
Service = S, Service = S2,
InitError = E, InitError = Err,
Future = R, Future = Fut,
> + Clone > + Clone
where where
F: FnMut(C, &mut T) -> R, S1: Service<Req>,
T: Service<Req>, F: FnMut(Cfg, &mut S1) -> Fut,
R: Future<Output = Result<S, E>>, Fut: Future<Output = Result<S2, Err>>,
S: Service<Req>, S2: Service<Req>,
{ {
ApplyConfigService { ApplyConfigService {
srv: Rc::new(RefCell::new((srv, f))), srv: Rc::new(RefCell::new((srv, f))),
_t: PhantomData, _phantom: PhantomData,
} }
} }
/// Convert `Fn(Config, &mut Service1) -> Future<Service2>` fn to a service factory /// Convert `Fn(Config, &mut ServiceFactory1) -> Future<ServiceFactory2>` fn to a service factory.
/// ///
/// Service1 get constructed from `T` factory. /// Service1 get constructed from `T` factory.
pub fn apply_cfg_factory<F, C, Req, T, R, S>( pub fn apply_cfg_factory<SF, Req, F, Cfg, Fut, S>(
factory: T, factory: SF,
f: F, f: F,
) -> impl ServiceFactory< ) -> impl ServiceFactory<
Req, Req,
Config = C, Config = Cfg,
Response = S::Response, Response = S::Response,
Error = S::Error, Error = S::Error,
Service = S, Service = S,
InitError = T::InitError, InitError = SF::InitError,
> + Clone > + Clone
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
T::InitError: From<T::Error>, SF::InitError: From<SF::Error>,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
ApplyConfigServiceFactory { ApplyConfigServiceFactory {
srv: Rc::new(RefCell::new((factory, f))), srv: Rc::new(RefCell::new((factory, f))),
_t: PhantomData, _phantom: PhantomData,
} }
} }
/// Convert `Fn(Config, &mut Server) -> Future<Service>` fn to NewService\ /// Convert `Fn(Config, &mut Server) -> Future<Service>` fn to NewService\
struct ApplyConfigService<F, C, Req, T, R, S, E> struct ApplyConfigService<S1, Req, F, Cfg, Fut, S2, Err>
where where
F: FnMut(C, &mut T) -> R, S1: Service<Req>,
T: Service<Req>, F: FnMut(Cfg, &mut S1) -> Fut,
R: Future<Output = Result<S, E>>, Fut: Future<Output = Result<S2, Err>>,
S: Service<Req>, S2: Service<Req>,
{ {
srv: Rc<RefCell<(T, F)>>, srv: Rc<RefCell<(S1, F)>>,
_t: PhantomData<(C, Req, R, S)>, _phantom: PhantomData<(Cfg, Req, Fut, S2)>,
} }
impl<F, C, Req, T, R, S, E> Clone for ApplyConfigService<F, C, Req, T, R, S, E> impl<S1, Req, F, Cfg, Fut, S2, Err> Clone for ApplyConfigService<S1, Req, F, Cfg, Fut, S2, Err>
where where
F: FnMut(C, &mut T) -> R, S1: Service<Req>,
T: Service<Req>, F: FnMut(Cfg, &mut S1) -> Fut,
R: Future<Output = Result<S, E>>, Fut: Future<Output = Result<S2, Err>>,
S: Service<Req>, S2: Service<Req>,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
ApplyConfigService { ApplyConfigService {
srv: self.srv.clone(), srv: self.srv.clone(),
_t: PhantomData, _phantom: PhantomData,
} }
} }
} }
impl<F, C, Req, T, R, S, E> ServiceFactory<Req> for ApplyConfigService<F, C, Req, T, R, S, E> impl<S1, Req, F, Cfg, Fut, S2, Err> ServiceFactory<Req>
for ApplyConfigService<S1, Req, F, Cfg, Fut, S2, Err>
where where
F: FnMut(C, &mut T) -> R, S1: Service<Req>,
T: Service<Req>, F: FnMut(Cfg, &mut S1) -> Fut,
R: Future<Output = Result<S, E>>, Fut: Future<Output = Result<S2, Err>>,
S: Service<Req>, S2: Service<Req>,
{ {
type Config = C; type Config = Cfg;
type Response = S::Response; type Response = S2::Response;
type Error = S::Error; type Error = S2::Error;
type Service = S; type Service = S2;
type InitError = E; type InitError = Err;
type Future = R; type Future = Fut;
fn new_service(&self, cfg: C) -> Self::Future { fn new_service(&self, cfg: Cfg) -> Self::Future {
let (t, f) = &mut *self.srv.borrow_mut(); let (t, f) = &mut *self.srv.borrow_mut();
f(cfg, t) f(cfg, t)
} }
} }
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService /// Convert `Fn(&Config) -> Future<Service>` fn to NewService
struct ApplyConfigServiceFactory<F, C, Req, T, R, S> struct ApplyConfigServiceFactory<SF, Req, F, Cfg, Fut, S>
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
srv: Rc<RefCell<(T, F)>>, srv: Rc<RefCell<(SF, F)>>,
_t: PhantomData<(C, Req, R, S)>, _phantom: PhantomData<(Cfg, Req, Fut, S)>,
} }
impl<F, C, Req, T, R, S> Clone for ApplyConfigServiceFactory<F, C, Req, T, R, S> impl<SF, Req, F, Cfg, Fut, S> Clone for ApplyConfigServiceFactory<SF, Req, F, Cfg, Fut, S>
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
srv: self.srv.clone(), srv: self.srv.clone(),
_t: PhantomData, _phantom: PhantomData,
} }
} }
} }
impl<F, C, Req, T, R, S> ServiceFactory<Req> for ApplyConfigServiceFactory<F, C, Req, T, R, S> impl<SF, Req, F, Cfg, Fut, S> ServiceFactory<Req>
for ApplyConfigServiceFactory<SF, Req, F, Cfg, Fut, S>
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, SF::InitError: From<SF::Error>,
T::InitError: From<T::Error>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
type Config = C; type Config = Cfg;
type Response = S::Response; type Response = S::Response;
type Error = S::Error; type Error = S::Error;
type Service = S; type Service = S;
type InitError = T::InitError; type InitError = SF::InitError;
type Future = ApplyConfigServiceFactoryResponse<F, C, Req, T, R, S>; type Future = ApplyConfigServiceFactoryResponse<SF, Req, F, Cfg, Fut, S>;
fn new_service(&self, cfg: C) -> Self::Future { fn new_service(&self, cfg: Cfg) -> Self::Future {
ApplyConfigServiceFactoryResponse { ApplyConfigServiceFactoryResponse {
cfg: Some(cfg), cfg: Some(cfg),
store: self.srv.clone(), store: self.srv.clone(),
@ -160,42 +162,43 @@ where
} }
#[pin_project::pin_project] #[pin_project::pin_project]
struct ApplyConfigServiceFactoryResponse<F, C, Req, T, R, S> struct ApplyConfigServiceFactoryResponse<SF, Req, F, Cfg, Fut, S>
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, SF::InitError: From<SF::Error>,
T::InitError: From<T::Error>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
cfg: Option<C>, cfg: Option<Cfg>,
store: Rc<RefCell<(T, F)>>, store: Rc<RefCell<(SF, F)>>,
#[pin] #[pin]
state: State<T, R, S, Req>, state: State<SF, Fut, S, Req>,
} }
#[pin_project::pin_project(project = StateProj)] #[pin_project::pin_project(project = StateProj)]
enum State<T, R, S, Req> enum State<SF, Fut, S, Req>
where where
T: ServiceFactory<Req, Config = ()>, SF: ServiceFactory<Req, Config = ()>,
T::InitError: From<T::Error>, SF::InitError: From<SF::Error>,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
A(#[pin] T::Future), A(#[pin] SF::Future),
B(T::Service), B(SF::Service),
C(#[pin] R), C(#[pin] Fut),
} }
impl<F, C, Req, T, R, S> Future for ApplyConfigServiceFactoryResponse<F, C, Req, T, R, S> impl<SF, Req, F, Cfg, Fut, S> Future
for ApplyConfigServiceFactoryResponse<SF, Req, F, Cfg, Fut, S>
where where
F: FnMut(C, &mut T::Service) -> R, SF: ServiceFactory<Req, Config = ()>,
T: ServiceFactory<Req, Config = ()>, SF::InitError: From<SF::Error>,
T::InitError: From<T::Error>, F: FnMut(Cfg, &mut SF::Service) -> Fut,
R: Future<Output = Result<S, T::InitError>>, Fut: Future<Output = Result<S, SF::InitError>>,
S: Service<Req>, S: Service<Req>,
{ {
type Output = Result<S, T::InitError>; type Output = Result<S, SF::InitError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut().project(); let mut this = self.as_mut().project();

View File

@ -14,17 +14,17 @@ pub type BoxService<Req, Res, Err> =
pub struct BoxServiceFactory<Cfg, Req, Res, Err, InitErr>(Inner<Cfg, Req, Res, Err, InitErr>); pub struct BoxServiceFactory<Cfg, Req, Res, Err, InitErr>(Inner<Cfg, Req, Res, Err, InitErr>);
/// Create boxed service factory /// Create boxed service factory
pub fn factory<T, Req>( pub fn factory<SF, Req>(
factory: T, factory: SF,
) -> BoxServiceFactory<T::Config, Req, T::Response, T::Error, T::InitError> ) -> BoxServiceFactory<SF::Config, Req, SF::Response, SF::Error, SF::InitError>
where where
T: ServiceFactory<Req> + 'static, SF: ServiceFactory<Req> + 'static,
Req: 'static, Req: 'static,
T::Response: 'static, SF::Response: 'static,
T::Service: 'static, SF::Service: 'static,
T::Future: 'static, SF::Future: 'static,
T::Error: 'static, SF::Error: 'static,
T::InitError: 'static, SF::InitError: 'static,
{ {
BoxServiceFactory(Box::new(FactoryWrapper { BoxServiceFactory(Box::new(FactoryWrapper {
factory, factory,
@ -75,33 +75,33 @@ where
} }
} }
struct FactoryWrapper<C, T, Req> struct FactoryWrapper<SF, Req, C>
where where
T: ServiceFactory<Req>, SF: ServiceFactory<Req>,
{ {
factory: T, factory: SF,
_t: PhantomData<(C, Req)>, _t: PhantomData<(C, Req)>,
} }
impl<C, T, Req, Res, Err, InitErr> ServiceFactory<Req> for FactoryWrapper<C, T, Req> impl<SF, Req, Cfg, Res, Err, InitErr> ServiceFactory<Req> for FactoryWrapper<SF, Req, Cfg>
where where
Req: 'static, Req: 'static,
Res: 'static, Res: 'static,
Err: 'static, Err: 'static,
InitErr: 'static, InitErr: 'static,
T: ServiceFactory<Req, Config = C, Response = Res, Error = Err, InitError = InitErr>, SF: ServiceFactory<Req, Config = Cfg, Response = Res, Error = Err, InitError = InitErr>,
T::Future: 'static, SF::Future: 'static,
T::Service: 'static, SF::Service: 'static,
<T::Service as Service<Req>>::Future: 'static, <SF::Service as Service<Req>>::Future: 'static,
{ {
type Response = Res; type Response = Res;
type Error = Err; type Error = Err;
type InitError = InitErr; type InitError = InitErr;
type Config = C; type Config = Cfg;
type Service = BoxService<Req, Res, Err>; type Service = BoxService<Req, Res, Err>;
type Future = BoxFuture<Self::Service, Self::InitError>; type Future = BoxFuture<Self::Service, Self::InitError>;
fn new_service(&self, cfg: C) -> Self::Future { fn new_service(&self, cfg: Cfg) -> Self::Future {
Box::pin( Box::pin(
self.factory self.factory
.new_service(cfg) .new_service(cfg)
@ -123,10 +123,10 @@ where
} }
} }
impl<T, Req, Res, Err> Service<Req> for ServiceWrapper<T, Req> impl<S, Req, Res, Err> Service<Req> for ServiceWrapper<S, Req>
where where
T: Service<Req, Response = Res, Error = Err>, S: Service<Req, Response = Res, Error = Err>,
T::Future: 'static, S::Future: 'static,
{ {
type Response = Res; type Response = Res;
type Error = Err; type Error = Err;

View File

@ -338,10 +338,10 @@ where
} }
} }
/// Convert object of type `T` to a service `S` /// Convert object of type `U` to a service `S`
pub fn into_service<U, S, Req>(tp: U) -> S pub fn into_service<I, S, Req>(tp: I) -> S
where where
U: IntoService<S, Req>, I: IntoService<S, Req>,
S: Service<Req>, S: Service<Req>,
{ {
tp.into_service() tp.into_service()

View File

@ -6,9 +6,9 @@ use super::{IntoServiceFactory, ServiceFactory};
/// ///
/// Note that this function consumes the receiving service factory and returns /// Note that this function consumes the receiving service factory and returns
/// a wrapped version of it. /// a wrapped version of it.
pub fn map_config<U, SF, S, Req, F, Cfg>(factory: U, f: F) -> MapConfig<SF, Req, F, Cfg> pub fn map_config<I, SF, S, Req, F, Cfg>(factory: I, f: F) -> MapConfig<SF, Req, F, Cfg>
where where
U: IntoServiceFactory<SF, Req>, I: IntoServiceFactory<SF, Req>,
SF: ServiceFactory<Req>, SF: ServiceFactory<Req>,
F: Fn(Cfg) -> SF::Config, F: Fn(Cfg) -> SF::Config,
{ {
@ -16,9 +16,9 @@ where
} }
/// Replace config with unit. /// Replace config with unit.
pub fn unit_config<U, SF, Cfg, Req>(factory: U) -> UnitConfig<SF, Cfg, Req> pub fn unit_config<I, SF, Cfg, Req>(factory: I) -> UnitConfig<SF, Cfg, Req>
where where
U: IntoServiceFactory<SF, Req>, I: IntoServiceFactory<SF, Req>,
SF: ServiceFactory<Req, Config = ()>, SF: ServiceFactory<Req, Config = ()>,
{ {
UnitConfig::new(factory.into_factory()) UnitConfig::new(factory.into_factory())

View File

@ -10,9 +10,9 @@ use crate::then::{ThenService, ThenServiceFactory};
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory}; use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
/// Construct new pipeline with one service in pipeline chain. /// Construct new pipeline with one service in pipeline chain.
pub fn pipeline<U, S, Req>(service: U) -> Pipeline<S, Req> pub fn pipeline<I, S, Req>(service: I) -> Pipeline<S, Req>
where where
U: IntoService<S, Req>, I: IntoService<S, Req>,
S: Service<Req>, S: Service<Req>,
{ {
Pipeline { Pipeline {
@ -22,9 +22,9 @@ where
} }
/// Construct new pipeline factory with one service factory. /// Construct new pipeline factory with one service factory.
pub fn pipeline_factory<U, SF, Req>(factory: U) -> PipelineFactory<SF, Req> pub fn pipeline_factory<I, SF, Req>(factory: I) -> PipelineFactory<SF, Req>
where where
U: IntoServiceFactory<SF, Req>, I: IntoServiceFactory<SF, Req>,
SF: ServiceFactory<Req>, SF: ServiceFactory<Req>,
{ {
PipelineFactory { PipelineFactory {
@ -52,14 +52,14 @@ where
/// ///
/// Note that this function consumes the receiving service and returns a /// Note that this function consumes the receiving service and returns a
/// wrapped version of it. /// wrapped version of it.
pub fn and_then<F, U>( pub fn and_then<I, S1>(
self, self,
service: F, service: I,
) -> Pipeline<impl Service<Req, Response = U::Response, Error = S::Error> + Clone, Req> ) -> Pipeline<impl Service<Req, Response = S1::Response, Error = S::Error> + Clone, Req>
where where
Self: Sized, Self: Sized,
F: IntoService<U, S::Response>, I: IntoService<S1, S::Response>,
U: Service<S::Response, Error = S::Error>, S1: Service<S::Response, Error = S::Error>,
{ {
Pipeline { Pipeline {
service: AndThenService::new(self.service, service.into_service()), service: AndThenService::new(self.service, service.into_service()),
@ -70,14 +70,14 @@ where
/// Apply function to specified service and use it as a next service in chain. /// Apply function to specified service and use it as a next service in chain.
/// ///
/// Short version of `pipeline_factory(...).and_then(apply_fn(...))` /// Short version of `pipeline_factory(...).and_then(apply_fn(...))`
pub fn and_then_apply_fn<U, S1, F, Fut, In, Res, Err>( pub fn and_then_apply_fn<I, S1, F, Fut, In, Res, Err>(
self, self,
service: U, service: I,
wrap_fn: F, wrap_fn: F,
) -> Pipeline<impl Service<Req, Response = Res, Error = Err> + Clone, Req> ) -> Pipeline<impl Service<Req, Response = Res, Error = Err> + Clone, Req>
where where
Self: Sized, Self: Sized,
U: IntoService<S1, In>, I: IntoService<S1, In>,
S1: Service<In>, S1: Service<In>,
F: FnMut(S::Response, &mut S1) -> Fut, F: FnMut(S::Response, &mut S1) -> Fut,
Fut: Future<Output = Result<Res, Err>>, Fut: Future<Output = Result<Res, Err>>,
@ -94,14 +94,14 @@ where
/// ///
/// Note that this function consumes the receiving pipeline and returns a /// Note that this function consumes the receiving pipeline and returns a
/// wrapped version of it. /// wrapped version of it.
pub fn then<F, U>( pub fn then<F, S1>(
self, self,
service: F, service: F,
) -> Pipeline<impl Service<Req, Response = U::Response, Error = S::Error> + Clone, Req> ) -> Pipeline<impl Service<Req, Response = S1::Response, Error = S::Error> + Clone, Req>
where where
Self: Sized, Self: Sized,
F: IntoService<U, Result<S::Response, S::Error>>, F: IntoService<S1, Result<S::Response, S::Error>>,
U: Service<Result<S::Response, S::Error>, Error = S::Error>, S1: Service<Result<S::Response, S::Error>, Error = S::Error>,
{ {
Pipeline { Pipeline {
service: ThenService::new(self.service, service.into_service()), service: ThenService::new(self.service, service.into_service()),
@ -161,13 +161,13 @@ where
} }
} }
impl<T: Service<Req>, Req> Service<Req> for Pipeline<T, Req> { impl<S: Service<Req>, Req> Service<Req> for Pipeline<S, Req> {
type Response = T::Response; type Response = S::Response;
type Error = T::Error; type Error = S::Error;
type Future = T::Future; type Future = S::Future;
#[inline] #[inline]
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), T::Error>> { fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), S::Error>> {
self.service.poll_ready(ctx) self.service.poll_ready(ctx)
} }
@ -188,25 +188,25 @@ where
SF: ServiceFactory<Req>, SF: ServiceFactory<Req>,
{ {
/// Call another service after call to this one has resolved successfully. /// Call another service after call to this one has resolved successfully.
pub fn and_then<F, U>( pub fn and_then<I, SF1>(
self, self,
factory: F, factory: I,
) -> PipelineFactory< ) -> PipelineFactory<
impl ServiceFactory< impl ServiceFactory<
Req, Req,
Response = U::Response, Response = SF1::Response,
Error = SF::Error, Error = SF::Error,
Config = SF::Config, Config = SF::Config,
InitError = SF::InitError, InitError = SF::InitError,
Service = impl Service<Req, Response = U::Response, Error = SF::Error> + Clone, Service = impl Service<Req, Response = SF1::Response, Error = SF::Error> + Clone,
> + Clone, > + Clone,
Req, Req,
> >
where where
Self: Sized, Self: Sized,
SF::Config: Clone, SF::Config: Clone,
F: IntoServiceFactory<U, SF::Response>, I: IntoServiceFactory<SF1, SF::Response>,
U: ServiceFactory< SF1: ServiceFactory<
SF::Response, SF::Response,
Config = SF::Config, Config = SF::Config,
Error = SF::Error, Error = SF::Error,
@ -222,9 +222,9 @@ where
/// Apply function to specified service and use it as a next service in chain. /// Apply function to specified service and use it as a next service in chain.
/// ///
/// Short version of `pipeline_factory(...).and_then(apply_fn_factory(...))` /// Short version of `pipeline_factory(...).and_then(apply_fn_factory(...))`
pub fn and_then_apply_fn<U, SF1, Fut, F, In, Res, Err>( pub fn and_then_apply_fn<I, SF1, Fut, F, In, Res, Err>(
self, self,
factory: U, factory: I,
wrap_fn: F, wrap_fn: F,
) -> PipelineFactory< ) -> PipelineFactory<
impl ServiceFactory< impl ServiceFactory<
@ -240,7 +240,7 @@ where
where where
Self: Sized, Self: Sized,
SF::Config: Clone, SF::Config: Clone,
U: IntoServiceFactory<SF1, In>, I: IntoServiceFactory<SF1, In>,
SF1: ServiceFactory<In, Config = SF::Config, InitError = SF::InitError>, SF1: ServiceFactory<In, Config = SF::Config, InitError = SF::InitError>,
F: FnMut(SF::Response, &mut SF1::Service) -> Fut + Clone, F: FnMut(SF::Response, &mut SF1::Service) -> Fut + Clone,
Fut: Future<Output = Result<Res, Err>>, Fut: Future<Output = Result<Res, Err>>,
@ -258,25 +258,25 @@ where
/// ///
/// Note that this function consumes the receiving pipeline and returns a /// Note that this function consumes the receiving pipeline and returns a
/// wrapped version of it. /// wrapped version of it.
pub fn then<F, U>( pub fn then<I, SF1>(
self, self,
factory: F, factory: I,
) -> PipelineFactory< ) -> PipelineFactory<
impl ServiceFactory< impl ServiceFactory<
Req, Req,
Response = U::Response, Response = SF1::Response,
Error = SF::Error, Error = SF::Error,
Config = SF::Config, Config = SF::Config,
InitError = SF::InitError, InitError = SF::InitError,
Service = impl Service<Req, Response = U::Response, Error = SF::Error> + Clone, Service = impl Service<Req, Response = SF1::Response, Error = SF::Error> + Clone,
> + Clone, > + Clone,
Req, Req,
> >
where where
Self: Sized, Self: Sized,
SF::Config: Clone, SF::Config: Clone,
F: IntoServiceFactory<U, Result<SF::Response, SF::Error>>, I: IntoServiceFactory<SF1, Result<SF::Response, SF::Error>>,
U: ServiceFactory< SF1: ServiceFactory<
Result<SF::Response, SF::Error>, Result<SF::Response, SF::Error>,
Config = SF::Config, Config = SF::Config,
Error = SF::Error, Error = SF::Error,
@ -342,16 +342,19 @@ where
} }
} }
impl<T: ServiceFactory<Req>, Req> ServiceFactory<Req> for PipelineFactory<T, Req> { impl<SF, Req> ServiceFactory<Req> for PipelineFactory<SF, Req>
type Config = T::Config; where
type Response = T::Response; SF: ServiceFactory<Req>,
type Error = T::Error; {
type Service = T::Service; type Config = SF::Config;
type InitError = T::InitError; type Response = SF::Response;
type Future = T::Future; type Error = SF::Error;
type Service = SF::Service;
type InitError = SF::InitError;
type Future = SF::Future;
#[inline] #[inline]
fn new_service(&self, cfg: T::Config) -> Self::Future { fn new_service(&self, cfg: SF::Config) -> Self::Future {
self.factory.new_service(cfg) self.factory.new_service(cfg)
} }
} }

View File

@ -8,11 +8,11 @@ use crate::transform_err::TransformMapInitErr;
use crate::{IntoServiceFactory, Service, ServiceFactory}; use crate::{IntoServiceFactory, Service, ServiceFactory};
/// Apply transform to a service. /// Apply transform to a service.
pub fn apply<T, S, U, Req>(t: T, factory: U) -> ApplyTransform<T, S, Req> pub fn apply<T, S, I, Req>(t: T, factory: I) -> ApplyTransform<T, S, Req>
where where
I: IntoServiceFactory<S, Req>,
S: ServiceFactory<Req>, S: ServiceFactory<Req>,
T: Transform<S::Service, Req, InitError = S::InitError>, T: Transform<S::Service, Req, InitError = S::InitError>,
U: IntoServiceFactory<S, Req>,
{ {
ApplyTransform::new(t, factory.into_factory()) ApplyTransform::new(t, factory.into_factory())
} }

View File

@ -103,14 +103,14 @@ where
/// |req: &Request| Some(span!(Level::INFO, "request", req.id)) /// |req: &Request| Some(span!(Level::INFO, "request", req.id))
/// ); /// );
/// ``` /// ```
pub fn trace<S, Req, U, F>( pub fn trace<S, Req, I, F>(
service_factory: U, service_factory: I,
make_span: F, make_span: F,
) -> ApplyTransform<TracingTransform<S::Service, S, F>, S, Req> ) -> ApplyTransform<TracingTransform<S::Service, S, F>, S, Req>
where where
I: IntoServiceFactory<S, Req>,
S: ServiceFactory<Req>, S: ServiceFactory<Req>,
F: Fn(&Req) -> Option<tracing::Span> + Clone, F: Fn(&Req) -> Option<tracing::Span> + Clone,
U: IntoServiceFactory<S, Req>,
{ {
apply( apply(
TracingTransform::new(make_span), TracingTransform::new(make_span),

View File

@ -165,21 +165,21 @@ where
pin_project! { pin_project! {
/// `TimeoutService` response future /// `TimeoutService` response future
#[derive(Debug)] #[derive(Debug)]
pub struct TimeoutServiceResponse<T, Req> pub struct TimeoutServiceResponse<S, Req>
where where
T: Service<Req> S: Service<Req>
{ {
#[pin] #[pin]
fut: T::Future, fut: S::Future,
sleep: Delay, sleep: Delay,
} }
} }
impl<T, Req> Future for TimeoutServiceResponse<T, Req> impl<S, Req> Future for TimeoutServiceResponse<S, Req>
where where
T: Service<Req>, S: Service<Req>,
{ {
type Output = Result<T::Response, TimeoutError<T::Error>>; type Output = Result<S::Response, TimeoutError<S::Error>>;
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();