From d342c2c714498d33891fa285a3c9ae991dc34769 Mon Sep 17 00:00:00 2001 From: Tom Karwowski Date: Mon, 7 Aug 2023 21:22:21 +0200 Subject: [PATCH] feat(server): add `Builder::local_addr()` (#3278) --- src/server/server.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/server/server.rs b/src/server/server.rs index c90eac3e53..cd34bb7b4a 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -629,6 +629,14 @@ impl Builder { self.incoming.set_sleep_on_errors(val); self } + + /// Returns the local address that the server will be bound to. + /// + /// This might be useful when knowing the address is required before calling `Builder::serve`, + /// but the address is not otherwise available (for e.g. when binding to port 0). + pub fn local_addr(&self) -> SocketAddr { + self.incoming.local_addr() + } } // Used by `Server` to optionally watch a `Connection` future.