From c2d73873cc8af7306305b6464b6bc8a68177f272 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 30 Aug 2018 17:54:59 -0700 Subject: [PATCH] rename Apply combinator --- src/service/apply.rs | 39 ++++++++++++++++++--------------------- src/service/mod.rs | 10 +++++----- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/service/apply.rs b/src/service/apply.rs index 0fa8d77b8..a39663d32 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -4,7 +4,7 @@ use futures::{Async, Future, Poll}; use {IntoNewService, NewService, Service}; /// `ApplyService` service combinator -pub struct ApplyService { +pub struct Apply { service: T, f: F, r: PhantomData, @@ -13,7 +13,7 @@ pub struct ApplyService { e: PhantomData, } -impl ApplyService +impl Apply where T: Service, T::Error: Into, @@ -33,7 +33,7 @@ where } } -impl Service for ApplyService +impl Service for Apply where T: Service, T::Error: Into, @@ -54,8 +54,8 @@ where } } -/// `Apply` new service combinator -pub struct Apply { +/// `ApplyNewService` new service combinator +pub struct ApplyNewService { service: T, f: F, r: PhantomData, @@ -64,13 +64,13 @@ pub struct Apply { e: PhantomData, } -impl Apply +impl ApplyNewService where T: NewService, F: Fn(Req, &mut T::Service) -> R, R: Future, { - /// Create new `Partial` new service instance + /// Create new `ApplyNewService` new service instance pub fn new>(f: F, service: F1) -> Self { Self { f, @@ -83,7 +83,7 @@ where } } -impl Clone for Apply +impl Clone for ApplyNewService where T: NewService + Clone, F: Fn(Req, &mut T::Service) -> R + Clone, @@ -101,7 +101,7 @@ where } } -impl NewService for Apply +impl NewService for ApplyNewService where T: NewService, T::Error: Into, @@ -111,17 +111,17 @@ where type Request = Req; type Response = Resp; type Error = Err; - type Service = ApplyService; + type Service = Apply; type InitError = T::InitError; - type Future = ApplyFuture; + type Future = ApplyNewServiceFuture; 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 +pub struct ApplyNewServiceFuture where T: NewService, F: Fn(Req, &mut T::Service) -> R, @@ -135,14 +135,14 @@ where e: PhantomData, } -impl ApplyFuture +impl ApplyNewServiceFuture where T: NewService, F: Fn(Req, &mut T::Service) -> R, R: Future, { fn new(fut: T::Future, f: F) -> Self { - ApplyFuture { + ApplyNewServiceFuture { f: Some(f), fut, r: PhantomData, @@ -153,22 +153,19 @@ where } } -impl Future for ApplyFuture +impl Future for ApplyNewServiceFuture where T: NewService, T::Error: Into, F: Fn(Req, &mut T::Service) -> R, R: Future, { - type Item = ApplyService; + type Item = Apply; type Error = T::InitError; fn poll(&mut self) -> Poll { if let Async::Ready(service) = self.fut.poll()? { - Ok(Async::Ready(ApplyService::new( - self.f.take().unwrap(), - service, - ))) + Ok(Async::Ready(Apply::new(self.f.take().unwrap(), service))) } else { Ok(Async::NotReady) } diff --git a/src/service/mod.rs b/src/service/mod.rs index fe9a24430..d8e13136e 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -10,7 +10,7 @@ mod map_init_err; mod map_request; 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_state_service::{FnStateNewService, FnStateService}; pub use self::map::{Map, MapNewService}; @@ -20,14 +20,14 @@ pub use self::map_request::{MapReq, MapReqNewService}; use {NewService, Service}; pub trait ServiceExt: Service { - fn apply(self, f: F) -> ApplyService + fn apply(self, f: F) -> Apply where Self: Sized, Self::Error: Into, F: Fn(Req, &mut Self) -> R, R: Future, { - ApplyService::new(f, self) + Apply::new(f, self) } fn and_then(self, service: F) -> AndThen @@ -57,14 +57,14 @@ pub trait ServiceExt: Service { } pub trait NewServiceExt: NewService { - fn apply(self, f: F) -> Apply + fn apply(self, f: F) -> ApplyNewService where Self: Sized, Self::Error: Into, F: Fn(Req, &mut Self::Service) -> R + Clone, R: Future, { - Apply::new(f, self) + ApplyNewService::new(f, self) } fn and_then(self, new_service: F) -> AndThenNewService