1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-01-03 13:58:44 +00:00

rename Apply combinator

This commit is contained in:
Nikolay Kim 2018-08-30 17:54:59 -07:00
parent 7ff24863ab
commit c2d73873cc
2 changed files with 23 additions and 26 deletions

View file

@ -4,7 +4,7 @@ use futures::{Async, Future, Poll};
use {IntoNewService, NewService, Service}; use {IntoNewService, NewService, Service};
/// `ApplyService` service combinator /// `ApplyService` service combinator
pub struct ApplyService<T, F, R, Req, Resp, Err> { pub struct Apply<T, F, R, Req, Resp, Err> {
service: T, service: T,
f: F, f: F,
r: PhantomData<R>, r: PhantomData<R>,
@ -13,7 +13,7 @@ pub struct ApplyService<T, F, R, Req, Resp, Err> {
e: PhantomData<Err>, e: PhantomData<Err>,
} }
impl<T, F, R, Req, Resp, Err> ApplyService<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> Apply<T, F, R, Req, Resp, Err>
where where
T: Service, T: Service,
T::Error: Into<Err>, T::Error: Into<Err>,
@ -33,7 +33,7 @@ where
} }
} }
impl<T, F, R, Req, Resp, Err> Service for ApplyService<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> Service for Apply<T, F, R, Req, Resp, Err>
where where
T: Service, T: Service,
T::Error: Into<Err>, T::Error: Into<Err>,
@ -54,8 +54,8 @@ where
} }
} }
/// `Apply` new service combinator /// `ApplyNewService` new service combinator
pub struct Apply<T, F, R, Req, Resp, Err> { pub struct ApplyNewService<T, F, R, Req, Resp, Err> {
service: T, service: T,
f: F, f: F,
r: PhantomData<R>, r: PhantomData<R>,
@ -64,13 +64,13 @@ pub struct Apply<T, F, R, Req, Resp, Err> {
e: PhantomData<Err>, e: PhantomData<Err>,
} }
impl<T, F, R, Req, Resp, Err> Apply<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> ApplyNewService<T, F, R, Req, Resp, Err>
where where
T: NewService, T: NewService,
F: Fn(Req, &mut T::Service) -> R, F: Fn(Req, &mut T::Service) -> R,
R: Future<Item = Resp, Error = Err>, R: Future<Item = Resp, Error = Err>,
{ {
/// Create new `Partial` 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>>(f: F, service: F1) -> Self {
Self { Self {
f, f,
@ -83,7 +83,7 @@ where
} }
} }
impl<T, F, R, Req, Resp, Err> Clone for Apply<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> Clone for ApplyNewService<T, F, R, Req, Resp, Err>
where where
T: NewService + Clone, T: NewService + Clone,
F: Fn(Req, &mut T::Service) -> R + Clone, F: Fn(Req, &mut T::Service) -> R + Clone,
@ -101,7 +101,7 @@ where
} }
} }
impl<T, F, R, Req, Resp, Err> NewService for Apply<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> NewService for ApplyNewService<T, F, R, Req, Resp, Err>
where where
T: NewService, T: NewService,
T::Error: Into<Err>, T::Error: Into<Err>,
@ -111,17 +111,17 @@ where
type Request = Req; type Request = Req;
type Response = Resp; type Response = Resp;
type Error = Err; type Error = Err;
type Service = ApplyService<T::Service, F, R, Req, Resp, Err>; type Service = Apply<T::Service, F, R, Req, Resp, Err>;
type InitError = T::InitError; type InitError = T::InitError;
type Future = ApplyFuture<T, F, R, Req, Resp, Err>; type Future = ApplyNewServiceFuture<T, F, R, Req, Resp, Err>;
fn new_service(&self) -> Self::Future { fn new_service(&self) -> Self::Future {
ApplyFuture::new(self.service.new_service(), self.f.clone()) ApplyNewServiceFuture::new(self.service.new_service(), self.f.clone())
} }
} }
pub struct ApplyFuture<T, F, R, Req, Resp, Err> pub struct ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
where where
T: NewService, T: NewService,
F: Fn(Req, &mut T::Service) -> R, F: Fn(Req, &mut T::Service) -> R,
@ -135,14 +135,14 @@ where
e: PhantomData<Err>, e: PhantomData<Err>,
} }
impl<T, F, R, Req, Resp, Err> ApplyFuture<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
where where
T: NewService, T: NewService,
F: Fn(Req, &mut T::Service) -> R, F: Fn(Req, &mut T::Service) -> R,
R: Future<Item = Resp, Error = Err>, R: Future<Item = Resp, Error = Err>,
{ {
fn new(fut: T::Future, f: F) -> Self { fn new(fut: T::Future, f: F) -> Self {
ApplyFuture { ApplyNewServiceFuture {
f: Some(f), f: Some(f),
fut, fut,
r: PhantomData, r: PhantomData,
@ -153,22 +153,19 @@ where
} }
} }
impl<T, F, R, Req, Resp, Err> Future for ApplyFuture<T, F, R, Req, Resp, Err> impl<T, F, R, Req, Resp, Err> Future for ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
where where
T: NewService, T: NewService,
T::Error: Into<Err>, T::Error: Into<Err>,
F: Fn(Req, &mut T::Service) -> R, F: Fn(Req, &mut T::Service) -> R,
R: Future<Item = Resp, Error = Err>, R: Future<Item = Resp, Error = Err>,
{ {
type Item = ApplyService<T::Service, F, R, Req, Resp, Err>; type Item = Apply<T::Service, F, R, Req, Resp, Err>;
type Error = T::InitError; type Error = T::InitError;
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(ApplyService::new( Ok(Async::Ready(Apply::new(self.f.take().unwrap(), service)))
self.f.take().unwrap(),
service,
)))
} else { } else {
Ok(Async::NotReady) Ok(Async::NotReady)
} }

View file

@ -10,7 +10,7 @@ mod map_init_err;
mod map_request; mod map_request;
pub use self::and_then::{AndThen, AndThenNewService}; pub use self::and_then::{AndThen, AndThenNewService};
pub use self::apply::{Apply, ApplyService}; pub use self::apply::{Apply, ApplyNewService};
pub use self::fn_service::{FnNewService, FnService}; pub use self::fn_service::{FnNewService, FnService};
pub use self::fn_state_service::{FnStateNewService, FnStateService}; pub use self::fn_state_service::{FnStateNewService, FnStateService};
pub use self::map::{Map, MapNewService}; pub use self::map::{Map, MapNewService};
@ -20,14 +20,14 @@ pub use self::map_request::{MapReq, MapReqNewService};
use {NewService, Service}; use {NewService, Service};
pub trait ServiceExt: Service { pub trait ServiceExt: Service {
fn apply<F, R, Req, Resp, Err>(self, f: F) -> ApplyService<Self, F, R, Req, Resp, Err> fn apply<F, R, Req, Resp, Err>(self, f: F) -> Apply<Self, F, R, Req, Resp, Err>
where where
Self: Sized, Self: Sized,
Self::Error: Into<Err>, Self::Error: Into<Err>,
F: Fn(Req, &mut Self) -> R, F: Fn(Req, &mut Self) -> R,
R: Future<Item = Resp, Error = Err>, R: Future<Item = Resp, Error = Err>,
{ {
ApplyService::new(f, self) Apply::new(f, self)
} }
fn and_then<F, B>(self, service: F) -> AndThen<Self, B> fn and_then<F, B>(self, service: F) -> AndThen<Self, B>
@ -57,14 +57,14 @@ pub trait ServiceExt: Service {
} }
pub trait NewServiceExt: NewService { pub trait NewServiceExt: NewService {
fn apply<F, R, Req, Resp, Err>(self, f: F) -> Apply<Self, F, R, Req, Resp, Err> fn apply<F, R, Req, Resp, Err>(self, f: F) -> ApplyNewService<Self, F, R, Req, Resp, Err>
where where
Self: Sized, Self: Sized,
Self::Error: Into<Err>, Self::Error: Into<Err>,
F: Fn(Req, &mut Self::Service) -> R + Clone, F: Fn(Req, &mut Self::Service) -> R + Clone,
R: Future<Item = Resp, Error = Err>, R: Future<Item = Resp, Error = Err>,
{ {
Apply::new(f, self) ApplyNewService::new(f, self)
} }
fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B> fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B>