Skip to main content

bind

Function bind 

Source
pub async fn bind<A>(addr: A) -> Result<TcpListener, ServerError>
where A: ToSocketAddrs + Display,
Expand description

Bind a TCP listener at addr.

Accepts anything Tokio can resolve to socket addresses — a SocketAddr, a "host:port" string (including a hostname, resolved via DNS), or any other [ToSocketAddrs] implementor — matching TcpListener::bind’s own flexibility so callers don’t have to pre-parse a config-supplied address string.

Pass a literal address with port 0 to let the OS assign an ephemeral port (useful in tests); read it back with listener.local_addr().