diff --git a/src/service/fn_service.rs b/src/service/fn_service.rs index 6eee6c9b..07c9df3a 100644 --- a/src/service/fn_service.rs +++ b/src/service/fn_service.rs @@ -6,7 +6,7 @@ use futures::{ }; use tower_service::{NewService, Service}; -use super::IntoNewService; +use super::{IntoNewService, IntoService}; pub struct FnService where @@ -68,6 +68,16 @@ where } } +impl IntoService> for F +where + F: Fn(Req) -> Fut + 'static, + Fut: IntoFuture, +{ + fn into_service(self) -> FnService { + FnService::new(self) + } +} + pub struct FnNewService where F: Fn(Req) -> Fut, diff --git a/src/service/mod.rs b/src/service/mod.rs index e6580f4d..250accf3 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -103,15 +103,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 +/// Trait for types that can be converted to a `Service` pub trait IntoService where T: Service, { - /// Create service + /// Convert to a `Service` fn into_service(self) -> T; } @@ -120,7 +120,7 @@ pub trait IntoNewService where T: NewService, { - /// Create service + /// Convert to an `NewService` fn into_new_service(self) -> T; } @@ -141,13 +141,3 @@ where self } } - -impl IntoService> for F -where - F: Fn(Req) -> Fut + 'static, - Fut: IntoFuture, -{ - fn into_service(self) -> FnService { - FnService::new(self) - } -}