1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-31 11:32:10 +01:00

change apply combinator

This commit is contained in:
Nikolay Kim 2018-09-17 15:53:41 -07:00
parent 39a18d6969
commit 3384bbfae2
2 changed files with 18 additions and 13 deletions

View File

@ -19,7 +19,7 @@ where
R: IntoFuture, R: IntoFuture,
{ {
/// Create new `Apply` combinator /// Create new `Apply` combinator
pub fn new(f: F, service: T) -> Self { pub fn new(service: T, f: F) -> Self {
Self { Self {
service, service,
f, f,
@ -79,7 +79,7 @@ where
R: IntoFuture, R: IntoFuture,
{ {
/// Create new `ApplyNewService` new service instance /// Create new `ApplyNewService` new service instance
pub fn new<F1: IntoNewService<T>>(f: F, service: F1) -> Self { pub fn new<F1: IntoNewService<T>>(service: F1, f: F) -> Self {
Self { Self {
f, f,
service: service.into_new_service(), service: service.into_new_service(),
@ -161,7 +161,7 @@ where
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Async::Ready(service) = self.fut.poll()? { if let Async::Ready(service) = self.fut.poll()? {
Ok(Async::Ready(Apply::new(self.f.take().unwrap(), service))) Ok(Async::Ready(Apply::new(service, self.f.take().unwrap())))
} else { } else {
Ok(Async::NotReady) Ok(Async::NotReady)
} }

View File

@ -24,14 +24,16 @@ pub use self::map_init_err::MapInitErr;
/// An extension trait for `Service`s that provides a variety of convenient /// An extension trait for `Service`s that provides a variety of convenient
/// adapters /// adapters
pub trait ServiceExt: Service { pub trait ServiceExt: Service {
fn apply<F, R, Req>(self, f: F) -> Apply<Self, F, R, Req> /// Apply function to specified service and use it as a next service in chain.
fn apply<S, F, R>(self, service: S, f: F) -> AndThen<Self, Apply<S, F, R, Self::Response>>
where where
Self: Sized, Self: Sized,
Self::Error: Into<<R::Future as Future>::Error>, S: Service,
F: Fn(Req, &mut Self) -> R, S::Error: Into<<R::Future as Future>::Error>,
R: IntoFuture, F: Fn(Self::Response, &mut S) -> R,
R: IntoFuture<Error = Self::Error>,
{ {
Apply::new(f, self) self.and_then(Apply::new(service, f))
} }
/// Call another service after call to this one has resolved successfully. /// Call another service after call to this one has resolved successfully.
@ -100,14 +102,17 @@ pub trait ServiceExt: Service {
} }
pub trait NewServiceExt: NewService { pub trait NewServiceExt: NewService {
fn apply<F, R, Req>(self, f: F) -> ApplyNewService<Self, F, R, Req> fn apply<S, F, R>(
self, service: S, f: F,
) -> AndThenNewService<Self, ApplyNewService<S, F, R, Self::Response>>
where where
Self: Sized, Self: Sized,
Self::Error: Into<<R::Future as Future>::Error>, S: NewService<InitError = Self::InitError>,
F: Fn(Req, &mut Self::Service) -> R + Clone, S::Error: Into<<R::Future as Future>::Error>,
R: IntoFuture, F: Fn(Self::Response, &mut S::Service) -> R + Clone,
R: IntoFuture<Error = Self::Error>,
{ {
ApplyNewService::new(f, self) self.and_then(ApplyNewService::new(service, f))
} }
fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B> fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B>