From a928d82895f341c6cab3291bc004690ccf50746f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 30 Aug 2018 09:26:27 -0700 Subject: [PATCH] rename Apply service --- src/connector.rs | 4 +--- src/service/apply.rs | 39 +++++++++++++++++++++------------------ src/service/mod.rs | 16 ++-------------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/connector.rs b/src/connector.rs index 6458f803e..7665a1c4f 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -90,9 +90,7 @@ impl Connector { Error = ConnectorError, InitError = E, > + Clone { - move || -> FutureResult, E> { - ok(Connector::new(cfg.clone(), opts)) - } + move || -> FutureResult, E> { ok(Connector::new(cfg.clone(), opts)) } } } diff --git a/src/service/apply.rs b/src/service/apply.rs index 15e31020b..03f4dd8ef 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -3,8 +3,8 @@ use std::marker::PhantomData; use futures::{Async, Future, Poll}; use {NewService, Service}; -/// `Apply` service combinator -pub struct Apply { +/// `ApplyService` service combinator +pub struct ApplyService { service: T, f: F, r: PhantomData, @@ -13,7 +13,7 @@ pub struct Apply { e: PhantomData, } -impl Apply +impl ApplyService where T: Service, F: Fn(Req, &mut T) -> R, @@ -32,7 +32,7 @@ where } } -impl Service for Apply +impl Service for ApplyService where T: Service, T::Error: Into, @@ -53,8 +53,8 @@ where } } -/// `ApplyNewService` new service combinator -pub struct ApplyNewService { +/// `Apply` new service combinator +pub struct Apply { service: T, f: F, r: PhantomData, @@ -63,7 +63,7 @@ pub struct ApplyNewService { e: PhantomData, } -impl ApplyNewService +impl Apply where T: NewService, F: Fn(Req, &mut T::Service) -> R, @@ -82,7 +82,7 @@ where } } -impl Clone for ApplyNewService +impl Clone for Apply where T: NewService + Clone, F: Fn(Req, &mut T::Service) -> R + Clone, @@ -100,7 +100,7 @@ where } } -impl NewService for ApplyNewService +impl NewService for Apply where T: NewService, T::Error: Into, @@ -110,17 +110,17 @@ where type Request = Req; type Response = Resp; type Error = Err; - type Service = Apply; + type Service = ApplyService; type InitError = T::InitError; - type Future = ApplyNewServiceFuture; + type Future = ApplyFuture; 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 +pub struct ApplyFuture where T: NewService, F: Fn(Req, &mut T::Service) -> R, @@ -134,14 +134,14 @@ where e: PhantomData, } -impl ApplyNewServiceFuture +impl ApplyFuture where T: NewService, F: Fn(Req, &mut T::Service) -> R, R: Future, { fn new(fut: T::Future, f: F) -> Self { - ApplyNewServiceFuture { + ApplyFuture { f: Some(f), fut, r: PhantomData, @@ -152,18 +152,21 @@ where } } -impl Future for ApplyNewServiceFuture +impl Future for ApplyFuture where T: NewService, F: Fn(Req, &mut T::Service) -> R, R: Future, { - type Item = Apply; + type Item = ApplyService; type Error = T::InitError; fn poll(&mut self) -> 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 { Ok(Async::NotReady) } diff --git a/src/service/mod.rs b/src/service/mod.rs index 2fdca0a61..81b6bff16 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -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( - f: F, service: F2, - ) -> ApplyNewService - where - T: NewService, - F: Fn(Req, &mut T::Service) -> R + Clone, - R: Future, - F2: IntoNewService, - { - ApplyNewService::new(f, service.into_new_service()) - } - fn and_then(self, new_service: F) -> AndThenNewService where Self: Sized,