next_addr_for_ip

Function next_addr_for_ip 

Source
pub fn next_addr_for_ip(ip: IpAddr) -> (PortGuard, SocketAddr)
Expand description

Allocates a unique port and returns a guard that keeps it reserved.

The returned PortGuard must be kept alive for as long as you need the port reserved. When the guard is dropped, the port is automatically released.

If the OS assigns a port that’s already reserved by another test, this function will automatically retry with a new port, ensuring each test gets a unique port.

§Example

let (_guard, addr) = next_addr_for_ip(IpAddr::V4(Ipv4Addr::LOCALHOST));
// Use addr for your test
// Port is automatically released when _guard goes out of scope