1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 19:12:56 +01:00

rename Apply service

This commit is contained in:
Nikolay Kim 2018-08-30 09:26:27 -07:00
parent e0513e4085
commit a928d82895
3 changed files with 24 additions and 35 deletions

View File

@ -90,9 +90,7 @@ impl<T: HostAware> Connector<T> {
Error = ConnectorError,
InitError = E,
> + Clone {
move || -> FutureResult<Connector<T>, E> {
ok(Connector::new(cfg.clone(), opts))
}
move || -> FutureResult<Connector<T>, E> { ok(Connector::new(cfg.clone(), opts)) }
}
}

View File

@ -3,8 +3,8 @@ use std::marker::PhantomData;
use futures::{Async, Future, Poll};
use {NewService, Service};
/// `Apply` service combinator
pub struct Apply<T, F, R, Req, Resp, Err> {
/// `ApplyService` service combinator
pub struct ApplyService<T, F, R, Req, Resp, Err> {
service: T,
f: F,
r: PhantomData<R>,
@ -13,7 +13,7 @@ pub struct Apply<T, F, R, Req, Resp, 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> ApplyService<T, F, R, Req, Resp, Err>
where
T: Service,
F: Fn(Req, &mut T) -> R,
@ -32,7 +32,7 @@ where
}
}
impl<T, F, R, Req, Resp, Err> Service for Apply<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> Service for ApplyService<T, F, R, Req, Resp, Err>
where
T: Service,
T::Error: Into<Err>,
@ -53,8 +53,8 @@ where
}
}
/// `ApplyNewService` new service combinator
pub struct ApplyNewService<T, F, R, Req, Resp, Err> {
/// `Apply` new service combinator
pub struct Apply<T, F, R, Req, Resp, Err> {
service: T,
f: F,
r: PhantomData<R>,
@ -63,7 +63,7 @@ pub struct ApplyNewService<T, F, R, Req, Resp, Err> {
e: PhantomData<Err>,
}
impl<T, F, R, Req, Resp, Err> ApplyNewService<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> Apply<T, F, R, Req, Resp, Err>
where
T: NewService,
F: Fn(Req, &mut T::Service) -> R,
@ -82,7 +82,7 @@ where
}
}
impl<T, F, R, Req, Resp, Err> Clone for ApplyNewService<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> Clone for Apply<T, F, R, Req, Resp, Err>
where
T: NewService + Clone,
F: Fn(Req, &mut T::Service) -> R + Clone,
@ -100,7 +100,7 @@ where
}
}
impl<T, F, R, Req, Resp, Err> NewService for ApplyNewService<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> NewService for Apply<T, F, R, Req, Resp, Err>
where
T: NewService,
T::Error: Into<Err>,
@ -110,17 +110,17 @@ where
type Request = Req;
type Response = Resp;
type Error = Err;
type Service = Apply<T::Service, F, R, Req, Resp, Err>;
type Service = ApplyService<T::Service, F, R, Req, Resp, Err>;
type InitError = T::InitError;
type Future = ApplyNewServiceFuture<T, F, R, Req, Resp, Err>;
type Future = ApplyFuture<T, F, R, Req, Resp, Err>;
fn new_service(&self) -> Self::Future {
ApplyNewServiceFuture::new(self.service.new_service(), self.f.clone())
ApplyFuture::new(self.service.new_service(), self.f.clone())
}
}
pub struct ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
pub struct ApplyFuture<T, F, R, Req, Resp, Err>
where
T: NewService,
F: Fn(Req, &mut T::Service) -> R,
@ -134,14 +134,14 @@ where
e: PhantomData<Err>,
}
impl<T, F, R, Req, Resp, Err> ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> ApplyFuture<T, F, R, Req, Resp, Err>
where
T: NewService,
F: Fn(Req, &mut T::Service) -> R,
R: Future<Item = Resp, Error = Err>,
{
fn new(fut: T::Future, f: F) -> Self {
ApplyNewServiceFuture {
ApplyFuture {
f: Some(f),
fut,
r: PhantomData,
@ -152,18 +152,21 @@ where
}
}
impl<T, F, R, Req, Resp, Err> Future for ApplyNewServiceFuture<T, F, R, Req, Resp, Err>
impl<T, F, R, Req, Resp, Err> Future for ApplyFuture<T, F, R, Req, Resp, Err>
where
T: NewService,
F: Fn(Req, &mut T::Service) -> R,
R: Future<Item = Resp, Error = Err>,
{
type Item = Apply<T::Service, F, R, Req, Resp, Err>;
type Item = ApplyService<T::Service, F, R, Req, Resp, Err>;
type Error = T::InitError;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Async::Ready(service) = self.fut.poll()? {
Ok(Async::Ready(Apply::new(self.f.take().unwrap(), service)))
Ok(Async::Ready(ApplyService::new(
self.f.take().unwrap(),
service,
)))
} else {
Ok(Async::NotReady)
}

View File

@ -1,4 +1,4 @@
use futures::{Future, IntoFuture};
use futures::IntoFuture;
mod and_then;
mod apply;
@ -10,7 +10,7 @@ mod map_init_err;
mod map_request;
pub use self::and_then::{AndThen, AndThenNewService};
pub use self::apply::{Apply, ApplyNewService};
pub use self::apply::{Apply, ApplyService};
pub use self::fn_service::{FnNewService, FnService};
pub use self::fn_state_service::{FnStateNewService, FnStateService};
pub use self::map::{Map, MapNewService};
@ -47,18 +47,6 @@ pub trait ServiceExt: Service {
}
pub trait NewServiceExt: NewService {
fn apply<T, F, R, Req, Resp, Err, F2>(
f: F, service: F2,
) -> ApplyNewService<T, F, R, Req, Resp, Err>
where
T: NewService,
F: Fn(Req, &mut T::Service) -> R + Clone,
R: Future<Item = Resp, Error = Err>,
F2: IntoNewService<T>,
{
ApplyNewService::new(f, service.into_new_service())
}
fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B>
where
Self: Sized,