diff --git a/rustfmt.toml b/rustfmt.toml index 63cb01141..2e19d1678 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ max_width = 96 reorder_imports = true -wrap_comments = true -fn_args_density = "Compressed" +#wrap_comments = true +#fn_args_density = "Compressed" #use_small_heuristics = false diff --git a/src/connector.rs b/src/connector.rs index d82f5dbc1..99c91e2da 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -173,19 +173,18 @@ impl Connector { Connector { resolver } } - // /// Create new default connector service - // pub fn new_service_with_config( - // cfg: ResolverConfig, - // opts: ResolverOpts, - // ) -> impl NewService< - // Connect, - // Response = (Connect, TcpStream), - // Error = ConnectorError, - // InitError = E, - // Service = impl Service + Clone, - // > + Clone { - // move || -> FutureResult { ok(Connector::new(cfg.clone(), opts)) } - // } + /// Create new default connector service + pub fn new_service_with_config( + cfg: ResolverConfig, + opts: ResolverOpts, + ) -> impl NewService< + Connect, + Response = (Connect, TcpStream), + Error = ConnectorError, + InitError = E, + > + Clone { + move || -> FutureResult { ok(Connector::new(cfg.clone(), opts)) } + } } impl Clone for Connector { diff --git a/src/service/and_then.rs b/src/service/and_then.rs index 953ba8dbb..0251f80b3 100644 --- a/src/service/and_then.rs +++ b/src/service/and_then.rs @@ -26,7 +26,6 @@ impl AndThen { impl Clone for AndThen where A: Clone, - B: Clone, { fn clone(&self) -> Self { AndThen { @@ -223,8 +222,7 @@ mod tests { use service::{NewServiceExt, Service, ServiceExt}; struct Srv1(Rc>); - impl Service for Srv1 { - type Request = &'static str; + impl Service<&'static str> for Srv1 { type Response = &'static str; type Error = (); type Future = FutureResult; @@ -234,7 +232,7 @@ mod tests { Ok(Async::Ready(())) } - fn call(&mut self, req: Self::Request) -> Self::Future { + fn call(&mut self, req: &'static str) -> Self::Future { ok(req) } } @@ -242,8 +240,7 @@ mod tests { #[derive(Clone)] struct Srv2(Rc>); - impl Service for Srv2 { - type Request = &'static str; + impl Service<&'static str> for Srv2 { type Response = (&'static str, &'static str); type Error = (); type Future = FutureResult; @@ -253,7 +250,7 @@ mod tests { Ok(Async::Ready(())) } - fn call(&mut self, req: Self::Request) -> Self::Future { + fn call(&mut self, req: &'static str) -> Self::Future { ok((req, "srv2")) } } diff --git a/src/service/apply.rs b/src/service/apply.rs index f4d559ae5..5eea74486 100644 --- a/src/service/apply.rs +++ b/src/service/apply.rs @@ -177,8 +177,7 @@ mod tests { #[derive(Clone)] struct Srv; - impl Service for Srv { - type Request = (); + impl Service<()> for Srv { type Response = (); type Error = (); type Future = FutureResult<(), ()>; diff --git a/src/service/from_err.rs b/src/service/from_err.rs index a82d662e2..dc4c4408d 100644 --- a/src/service/from_err.rs +++ b/src/service/from_err.rs @@ -162,8 +162,7 @@ mod tests { use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; struct Srv; - impl Service for Srv { - type Request = (); + impl Service<()> for Srv { type Response = (); type Error = (); type Future = FutureResult<(), ()>; diff --git a/src/service/map.rs b/src/service/map.rs index 7095e9c07..38e37a272 100644 --- a/src/service/map.rs +++ b/src/service/map.rs @@ -192,8 +192,7 @@ mod tests { use service::{IntoNewService, NewServiceExt, Service, ServiceExt}; struct Srv; - impl Service for Srv { - type Request = (); + impl Service<()> for Srv { type Response = (); type Error = (); type Future = FutureResult<(), ()>; diff --git a/src/service/map_err.rs b/src/service/map_err.rs index 1e8f5de7d..6b6cc7ce1 100644 --- a/src/service/map_err.rs +++ b/src/service/map_err.rs @@ -194,8 +194,7 @@ mod tests { struct Srv; - impl Service for Srv { - type Request = (); + impl Service<()> for Srv { type Response = (); type Error = (); type Future = FutureResult<(), ()>; diff --git a/src/service/mod.rs b/src/service/mod.rs index e944d29c9..3952a8016 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -231,6 +231,23 @@ pub trait NewServiceExt: NewService { } } +impl NewService for F +where + F: Fn() -> R, + R: IntoFuture, + S: Service, +{ + type Response = S::Response; + type Error = S::Error; + type Service = S; + type InitError = E; + type Future = R::Future; + + fn new_service(&self) -> Self::Future { + (*self)().into_future() + } +} + impl ServiceExt for T where T: Service {} impl NewServiceExt for T where T: NewService {} diff --git a/src/service/then.rs b/src/service/then.rs index d48ac4b6b..313ab725b 100644 --- a/src/service/then.rs +++ b/src/service/then.rs @@ -26,7 +26,6 @@ impl Then { impl Clone for Then where A: Clone, - B: Clone, { fn clone(&self) -> Self { Then { @@ -231,8 +230,7 @@ mod tests { #[derive(Clone)] struct Srv1(Rc>); - impl Service for Srv1 { - type Request = Result<&'static str, &'static str>; + impl Service> for Srv1 { type Response = &'static str; type Error = (); type Future = FutureResult; @@ -242,7 +240,7 @@ mod tests { Ok(Async::Ready(())) } - fn call(&mut self, req: Self::Request) -> Self::Future { + fn call(&mut self, req: Result<&'static str, &'static str>) -> Self::Future { match req { Ok(msg) => ok(msg), Err(_) => err(()), @@ -252,8 +250,7 @@ mod tests { struct Srv2(Rc>); - impl Service for Srv2 { - type Request = Result<&'static str, ()>; + impl Service> for Srv2 { type Response = (&'static str, &'static str); type Error = (); type Future = FutureResult; @@ -263,7 +260,7 @@ mod tests { Ok(Async::Ready(())) } - fn call(&mut self, req: Self::Request) -> Self::Future { + fn call(&mut self, req: Result<&'static str, ()>) -> Self::Future { match req { Ok(msg) => ok((msg, "ok")), Err(()) => ok(("srv2", "err")),