the Server::listen call currently takes an &str for both host and port. This gets fed into a format! call, using the a str impl of ToSocketAddr.
IMHO, there is no opinion to stringly-type these parameters. Taking a std::net::IpAddr and a u16 does exactly the same, with stronger typing. The combination (IpAddr, u16) even has a ToSocketAddrs-impl, so it can be directly passed into the TcpListener.
As discussed on users.rust-lang, this would add some boilerplate on the user-side to create the IpAddr:
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); // verbose, guaranteed to work...
"127.0.0.1".parse().expect("couldn't parse IP address") // not much better...
the Server::listen call currently takes an
&strfor both host and port. This gets fed into aformat!call, using the a str impl of ToSocketAddr.IMHO, there is no opinion to stringly-type these parameters. Taking a
std::net::IpAddrand a u16 does exactly the same, with stronger typing. The combination(IpAddr, u16)even has a ToSocketAddrs-impl, so it can be directly passed into the TcpListener.As discussed on users.rust-lang, this would add some boilerplate on the user-side to create the IpAddr: