nu-utils 0.112.1

Nushell utility functions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::{
    io,
    net::{Ipv4Addr, SocketAddr, TcpListener},
};

pub fn reserve_local_addr() -> io::Result<SocketAddr> {
    let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0))?;
    let addr = listener.local_addr()?;
    // The `TcpListener` impl for WASM does not implement `Drop` for some reason.
    #[cfg_attr(target_arch = "wasm32", expect(clippy::drop_non_drop))]
    drop(listener);
    Ok(addr)
}