diff --git a/src/lib.rs b/src/lib.rs index 2f694c7d7..272339e2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,7 +63,7 @@ mod worker; pub use configurable::{IntoNewConfigurableService, NewConfigurableService}; pub use server::Server; -pub use service::{IntoNewService, IntoService, NewServiceExt, ServiceExt}; +pub use service::{NewServiceExt, ServiceExt}; /// Pause accepting incoming connections /// diff --git a/src/service/and_then.rs b/src/service/and_then.rs index 2d248667f..0d4f22373 100644 --- a/src/service/and_then.rs +++ b/src/service/and_then.rs @@ -4,8 +4,6 @@ use std::rc::Rc; use futures::{Async, Future, Poll}; use tower_service::{NewService, Service}; -use super::IntoNewService; - /// `AndThen` service combinator pub struct AndThen { a: A, @@ -114,11 +112,8 @@ where B: NewService, { /// Create new `AndThen` combinator - pub fn new>(a: A, f: F) -> Self { - Self { - a, - b: f.into_new_service(), - } + pub fn new>(a: A, f: F) -> Self { + Self { a, b: f.into() } } } diff --git a/src/service/apply.rs b/src/service/apply.rs index 58755f6fa..b688a8c12 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -1,7 +1,8 @@ use std::marker::PhantomData; use futures::{Async, Future, IntoFuture, Poll}; -use {IntoNewService, NewService, Service}; + +use {NewService, Service}; /// `Apply` service combinator pub struct Apply { @@ -62,10 +63,10 @@ where R: IntoFuture, { /// Create new `ApplyNewService` new service instance - pub fn new>(f: F, service: F1) -> Self { + pub fn new>(f: F, service: F1) -> Self { Self { f, - service: service.into_new_service(), + service: service.into(), r: PhantomData, } } diff --git a/src/service/fn_service.rs b/src/service/fn_service.rs index 6eee6c9be..e08770d70 100644 --- a/src/service/fn_service.rs +++ b/src/service/fn_service.rs @@ -6,8 +6,6 @@ use futures::{ }; use tower_service::{NewService, Service}; -use super::IntoNewService; - pub struct FnService where F: Fn(Req) -> Fut, @@ -113,14 +111,13 @@ where } } -impl IntoNewService> - for F +impl From for FnNewService where F: Fn(Req) -> Fut + Clone + 'static, Fut: IntoFuture, { - fn into_new_service(self) -> FnNewService { - FnNewService::new(self) + fn from(f: F) -> FnNewService { + FnNewService::new(f) } } diff --git a/src/service/fn_state_service.rs b/src/service/fn_state_service.rs index 4a76ee363..f423c311d 100644 --- a/src/service/fn_state_service.rs +++ b/src/service/fn_state_service.rs @@ -3,8 +3,6 @@ use std::marker; use futures::{Async, Future, IntoFuture, Poll}; use tower_service::{NewService, Service}; -use super::IntoNewService; - pub struct FnStateService where F: Fn(&mut S, Req) -> Fut, @@ -113,8 +111,8 @@ where } } -impl - IntoNewService> for (F1, F2) +impl From<(F1, F2)> + for FnStateNewService where S: 'static, F1: Fn(&mut S, Req) -> Fut1 + Clone + 'static, @@ -126,10 +124,8 @@ where Err1: 'static, Err2: 'static, { - fn into_new_service( - self, - ) -> FnStateNewService { - FnStateNewService::new(self.0, self.1) + fn from(data: (F1, F2)) -> FnStateNewService { + FnStateNewService::new(data.0, data.1) } } diff --git a/src/service/mod.rs b/src/service/mod.rs index 940ab861d..1066f372b 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -33,10 +33,10 @@ pub trait ServiceExt: Service { fn and_then(self, service: F) -> AndThen where Self: Sized, - F: IntoService, + F: Into, B: Service, { - AndThen::new(self, service.into_service()) + AndThen::new(self, service.into()) } fn map(self, f: F) -> Map @@ -70,7 +70,7 @@ pub trait NewServiceExt: NewService { fn and_then(self, new_service: F) -> AndThenNewService where Self: Sized, - F: IntoNewService, + F: Into, B: NewService< Request = Self::Response, Error = Self::Error, @@ -113,51 +113,15 @@ pub trait NewServiceExt: NewService { } } -impl ServiceExt for T {} -impl NewServiceExt for T {} +impl ServiceExt for T where T: Service {} +impl NewServiceExt for T where T: NewService {} -/// Trait for types that can be converted to a Service -pub trait IntoService -where - T: Service, -{ - /// Create service - fn into_service(self) -> T; -} - -/// Trait for types that can be converted to a Service -pub trait IntoNewService -where - T: NewService, -{ - /// Create service - fn into_new_service(self) -> T; -} - -impl IntoService for T -where - T: Service, -{ - fn into_service(self) -> T { - self - } -} - -impl IntoNewService for T -where - T: NewService, -{ - fn into_new_service(self) -> T { - self - } -} - -impl IntoService> for F +impl From for FnService where F: Fn(Req) -> Fut + 'static, Fut: IntoFuture, { - fn into_service(self) -> FnService { - FnService::new(self) + fn from(f: F) -> FnService { + FnService::new(f) } } diff --git a/src/stream.rs b/src/stream.rs index f0ef120ec..104d444cf 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -2,7 +2,7 @@ use futures::unsync::mpsc; use futures::{Async, Future, Poll, Stream}; use tokio::executor::current_thread::spawn; -use super::{IntoService, Service}; +use super::Service; pub struct StreamDispatcher { stream: S, @@ -18,12 +18,12 @@ where T: Service, Response = (), Error = ()>, T::Future: 'static, { - pub fn new>(stream: S, service: F) -> Self { + pub fn new>(stream: S, service: F) -> Self { let (stop_tx, stop_rx) = mpsc::unbounded(); StreamDispatcher { stream, item: None, - service: service.into_service(), + service: service.into(), stop_rx, stop_tx, }