Skip to content

consider stronger typing for Server::listen arguments #70

Description

@juleskers

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...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions