Skip to content

Commit 4c0fdeb

Browse files
committed
Rollup merge of #33167 - benaryorg:master, r=alexcrichton
clarify documentation of TcpStream::connect() for multiple valid addresses I am not sure how the UDP part of the stdlib behaves when passing multiple valid addresses, but it should be mentioned as there are legit use cases for [`impl<'a> ToSocketAddrs for &'a [SocketAddr]`](http://doc.rust-lang.org/nightly/std/net/trait.ToSocketAddrs.html), a TCP fallback only being one. Just a little example program for anyone willing to enhance the documentation further: ```rust use std::net::SocketAddr; use std::net::ToSocketAddrs; use std::net::TcpStream; fn main() { let v: Vec<SocketAddr> = vec! [ "127.0.0.1:1338".to_socket_addrs().unwrap().next().unwrap(), "127.0.0.1:1337".to_socket_addrs().unwrap().next().unwrap(), "127.0.0.1:1339".to_socket_addrs().unwrap().next().unwrap(), ]; let stream = TcpStream::connect(&v[..]).unwrap(); } ```
2 parents b588f69 + 68a18c4 commit 4c0fdeb

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libstd/net/tcp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ impl TcpStream {
8686
/// `addr` is an address of the remote host. Anything which implements
8787
/// `ToSocketAddrs` trait can be supplied for the address; see this trait
8888
/// documentation for concrete examples.
89+
/// In case `ToSocketAddrs::to_socket_addrs()` returns more than one entry,
90+
/// then the first valid and reachable address is used.
8991
#[stable(feature = "rust1", since = "1.0.0")]
9092
pub fn connect<A: ToSocketAddrs>(addr: A) -> io::Result<TcpStream> {
9193
super::each_addr(addr, net_imp::TcpStream::connect).map(TcpStream)

0 commit comments

Comments
 (0)