i noticed this when changing my implementation from using connect to connect_timeout
std::net::TcpStream::connect accepts string since it accepts ToSocketAddr trait as parameter.
while connect_timeout doesn't do the same.
Unfortunately, adding trait parameters to functions is strictly speaking a breaking change, because the fully elaborated form of a function includes an empty turbofish, which would then stop working if a generic parameter is introduced. Adding a generic parameter would require default generic arguments for functions, which is a complicated bag of rabbit holes due to not quite actually being a normal default to work how people expect.
connect accepts A: ToSocketAddrs, which might resolve to multiple SocketAddr. It then tries to connect to them in order, returning with the first successful one.
connect_timeout specifically calls out directly why it takes a single SocketAddr:
Unlike connect , connect_timeout takes a single SocketAddr since timeout must be applied to individual addresses.
That makes it predictable. Taking ToSocketAddrs could make it wait arbitrarily long, depending on how many addresses the endpoint resolves too.
If that's the behavior you want it's at least easy enough to implement yourself.
As an aside, do you have links to issues about this? I’ve run into wanting defaults for type generic functions when making APIs a few times, and would be interested in knowing more about why it doesn’t work.
I'm not on the libs team and thus not responsible for this, but given that there is an explicit comment on why it does it the way it does I'd say it's very unlikely to change.