From a91b9a2f9e82374efb640a1c764125145ee41871 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 17 Sep 2018 16:16:42 -0700 Subject: [PATCH] better ergonomics for aply combinator --- src/service/apply.rs | 6 +++--- src/service/mod.rs | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/service/apply.rs b/src/service/apply.rs index 7d1bbabc..8a9ec1ed 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use futures::{Async, Future, IntoFuture, Poll}; -use super::{IntoNewService, NewService, Service}; +use super::{IntoNewService, IntoService, NewService, Service}; /// `Apply` service combinator pub struct Apply { @@ -19,9 +19,9 @@ where R: IntoFuture, { /// Create new `Apply` combinator - pub fn new(service: T, f: F) -> Self { + pub fn new>(service: I, f: F) -> Self { Self { - service, + service: service.into_service(), f, r: PhantomData, } diff --git a/src/service/mod.rs b/src/service/mod.rs index e5fc63a5..57c3b574 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -24,16 +24,20 @@ pub use self::map_init_err::MapInitErr; /// An extension trait for `Service`s that provides a variety of convenient /// adapters pub trait ServiceExt: Service { - /// Apply function to specified service and use it as a next service in chain. - fn apply(self, service: S, f: F) -> AndThen> + /// Apply function to specified service and use it as a next service in + /// chain. + fn apply( + self, service: I, f: F, + ) -> AndThen> where Self: Sized, S: Service, S::Error: Into<::Error>, + I: IntoService, F: Fn(Self::Response, &mut S) -> R, R: IntoFuture, { - self.and_then(Apply::new(service, f)) + self.and_then(Apply::new(service.into_service(), f)) } /// Call another service after call to this one has resolved successfully. @@ -102,13 +106,14 @@ pub trait ServiceExt: Service { } pub trait NewServiceExt: NewService { - fn apply( - self, service: S, f: F, + fn apply( + self, service: I, f: F, ) -> AndThenNewService> where Self: Sized, S: NewService, S::Error: Into<::Error>, + I: IntoNewService, F: Fn(Self::Response, &mut S::Service) -> R + Clone, R: IntoFuture, {