Skip to content

Commit 5668fb9

Browse files
committed
feat: add local address getter to server builder
1 parent 0ff6213 commit 5668fb9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/server/server.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ impl<E> Builder<AddrIncoming, E> {
594594
self.incoming.set_sleep_on_errors(val);
595595
self
596596
}
597+
598+
/// Returns the local address that the server will be bound to.
599+
///
600+
/// This might be useful when knowing the address is required before calling `Builder::serve`,
601+
/// but the address is not otherwise available (for e.g. when binding to port 0).
602+
pub fn local_addr(&self) -> SocketAddr {
603+
self.incoming.local_addr()
604+
}
597605
}
598606

599607
// Used by `Server` to optionally watch a `Connection` future.

0 commit comments

Comments
 (0)