mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 21:22:57 +01:00
rename Apply service
This commit is contained in:
parent
e0513e4085
commit
a928d82895
@ -90,9 +90,7 @@ impl<T: HostAware> Connector<T> {
|
|||||||
Error = ConnectorError,
|
Error = ConnectorError,
|
||||||
InitError = E,
|
InitError = E,
|
||||||
> + Clone {
|
> + Clone {
|
||||||
move || -> FutureResult<Connector<T>, E> {
|
move || -> FutureResult<Connector<T>, E> { ok(Connector::new(cfg.clone(), opts)) }
|
||||||
ok(Connector::new(cfg.clone(), opts))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ use std::marker::PhantomData;
|
|||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
use {NewService, Service};
|
use {NewService, Service};
|
||||||
|
|
||||||
/// `Apply` service combinator
|
/// `ApplyService` service combinator
|
||||||
pub struct Apply<T, F, R, Req, Resp, Err> {
|
pub struct ApplyService<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 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> ApplyService<T, F, R, Req, Resp, Err>
|
||||||
where
|
where
|
||||||
T: Service,
|
T: Service,
|
||||||
F: Fn(Req, &mut T) -> R,
|
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
|
where
|
||||||
T: Service,
|
T: Service,
|
||||||
T::Error: Into<Err>,
|
T::Error: Into<Err>,
|
||||||
@ -53,8 +53,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `ApplyNewService` new service combinator
|
/// `Apply` new service combinator
|
||||||
pub struct ApplyNewService<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>,
|
||||||
@ -63,7 +63,7 @@ pub struct ApplyNewService<T, F, R, Req, Resp, Err> {
|
|||||||
e: PhantomData<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
|
where
|
||||||
T: NewService,
|
T: NewService,
|
||||||
F: Fn(Req, &mut T::Service) -> R,
|
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
|
where
|
||||||
T: NewService + Clone,
|
T: NewService + Clone,
|
||||||
F: Fn(Req, &mut T::Service) -> R + 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
|
where
|
||||||
T: NewService,
|
T: NewService,
|
||||||
T::Error: Into<Err>,
|
T::Error: Into<Err>,
|
||||||
@ -110,17 +110,17 @@ where
|
|||||||
type Request = Req;
|
type Request = Req;
|
||||||
type Response = Resp;
|
type Response = Resp;
|
||||||
type Error = Err;
|
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 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 {
|
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
|
where
|
||||||
T: NewService,
|
T: NewService,
|
||||||
F: Fn(Req, &mut T::Service) -> R,
|
F: Fn(Req, &mut T::Service) -> R,
|
||||||
@ -134,14 +134,14 @@ where
|
|||||||
e: PhantomData<Err>,
|
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
|
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 {
|
||||||
ApplyNewServiceFuture {
|
ApplyFuture {
|
||||||
f: Some(f),
|
f: Some(f),
|
||||||
fut,
|
fut,
|
||||||
r: PhantomData,
|
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
|
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>,
|
||||||
{
|
{
|
||||||
type Item = Apply<T::Service, F, R, Req, Resp, Err>;
|
type Item = ApplyService<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(Apply::new(self.f.take().unwrap(), service)))
|
Ok(Async::Ready(ApplyService::new(
|
||||||
|
self.f.take().unwrap(),
|
||||||
|
service,
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use futures::{Future, IntoFuture};
|
use futures::IntoFuture;
|
||||||
|
|
||||||
mod and_then;
|
mod and_then;
|
||||||
mod apply;
|
mod apply;
|
||||||
@ -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, ApplyNewService};
|
pub use self::apply::{Apply, ApplyService};
|
||||||
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};
|
||||||
@ -47,18 +47,6 @@ pub trait ServiceExt: Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait NewServiceExt: NewService {
|
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>
|
fn and_then<F, B>(self, new_service: F) -> AndThenNewService<Self, B>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
Loading…
Reference in New Issue
Block a user