pub async fn bind(addr: SocketAddr) -> Result<TcpListener>Expand description
Open a TCP listener that will be passed to ControlServer::serve.
Pass a port of 0 to let the OS assign a free port; read it back
with TcpListener::local_addr after the call returns.
This is a free function rather than an associated function on the
generic ControlServer so callers can open the socket before
constructing state, without needing a turbofish to pin H.
Always bind to a loopback address (127.0.0.1) in practice: the
control plane carries no authentication and is intended only for
local developer use.
§Errors
Returns an std::io::Error if the bind fails (address already in
use, permission denied, etc.).
§Example
use std::net::SocketAddr;
use lightshuttle_control::bind;
// Loopback only: the control plane has no authentication.
let addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
let listener = bind(addr).await?;
let port = listener.local_addr()?.port();
println!("control plane listening on port {port}");