Skip to content

Commit d342c2c

Browse files
authored
feat(server): add Builder::local_addr() (#3278)
1 parent 45aa624 commit d342c2c

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
@@ -629,6 +629,14 @@ impl<E> Builder<AddrIncoming, E> {
629629
self.incoming.set_sleep_on_errors(val);
630630
self
631631
}
632+
633+
/// Returns the local address that the server will be bound to.
634+
///
635+
/// This might be useful when knowing the address is required before calling `Builder::serve`,
636+
/// but the address is not otherwise available (for e.g. when binding to port 0).
637+
pub fn local_addr(&self) -> SocketAddr {
638+
self.incoming.local_addr()
639+
}
632640
}
633641

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

0 commit comments

Comments
 (0)