From 8108f195807a83afd26a3c49a3bde580eb363cf7 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 29 Nov 2018 17:17:02 -1000 Subject: [PATCH] update tests --- rustfmt.toml | 4 ++-- src/connector.rs | 25 ++++++++++++------------- src/service/and_then.rs | 11 ++++------- src/service/apply.rs | 3 +-- src/service/from_err.rs | 3 +-- src/service/map.rs | 3 +-- src/service/map_err.rs | 3 +-- src/service/mod.rs | 17 +++++++++++++++++ src/service/then.rs | 11 ++++------- 9 files changed, 43 insertions(+), 37 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 63cb0114..2e19d167 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 d82f5dbc..99c91e2d 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 953ba8db..0251f80b 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 f4d559ae..5eea7448 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 a82d662e..dc4c4408 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 7095e9c0..38e37a27 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 1e8f5de7..6b6cc7ce 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 e944d29c..3952a801 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 d48ac4b6..313ab725 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")),