TcpListener::bind/TcpStream::connect (&str, Int), &str and SocketAddr{...} overrides #14755
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cc @alexcrichton
In #13919 we changed
TcpStream::connect
to accept a host and a port parameter instead of a somewhat "uncomfortable"SocketAddr
. There were some reasonable complaints following the merge that basically said sometimes you might want a SocketAddr for various different reasons, and that carting strings around everywhere might be painful in certain situations.@huonw and @zargony suggested it might be better for
TcpStream::connect
andTcpListener::bind
to use traits so that they can operate with various different types of arguments. I gave that a shot, and I think the results are really nice.This change allows the following:
It would also be trivial to add support for e.g. (IpAddr, Int) tuples too, but I didn't want to get too carried away :)
I think this PR needs some work before it gets merged. In particular,
connect_timeout
hasn't been modified, and I'm not sure that we want two distinct traits (ToBindSocketAddr
andToSocketAddrs
) for very similar use-cases. Figure it's at a point where it'll probably drive some discussion, though.