From da16ed62a3f478800f7a44c49acca4b109e4448b Mon Sep 17 00:00:00 2001 From: Peter Wilkins Date: Tue, 12 Nov 2019 18:08:36 +0000 Subject: [PATCH] fix(server): allow `Server::local_addr` to be called with custom executor (#2009) add generic for the executor to server impl block resolves https://github.com/hyperium/hyper/issues/1988 --- examples/single_threaded.rs | 7 ++++--- src/server/mod.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/single_threaded.rs b/examples/single_threaded.rs index d39158bc45..c0b8131840 100644 --- a/examples/single_threaded.rs +++ b/examples/single_threaded.rs @@ -37,14 +37,15 @@ fn main() { let server = Server::bind(&addr) .executor(exec) - .serve(new_service) - .map_err(|e| eprintln!("server error: {}", e)); + .serve(new_service); println!("Listening on http://{}", addr); + assert_eq!(addr, server.local_addr()); + current_thread::Runtime::new() .expect("rt new") - .spawn(server) + .spawn(server.map_err(|e| eprintln!("server error: {}", e))) .run() .expect("rt run"); } diff --git a/src/server/mod.rs b/src/server/mod.rs index b55af69875..57a394f10a 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -133,7 +133,7 @@ impl Server { } #[cfg(feature = "runtime")] -impl Server { +impl Server { /// Returns the local address that this server is bound to. pub fn local_addr(&self) -> SocketAddr { self.spawn_all.local_addr()