提交 bb4d1491 编写于 作者: B bors

Auto merge of #44913 - leavehouse:patch-1, r=BurntSushi

Fix TcpStream::local_addr docs example code

The local address's port is not 8080 in this example, that's the remote peer address port. On my machine, the local address is different every time, so I've changed `assert_eq` to only test the IP address
......@@ -194,12 +194,12 @@ pub fn peer_addr(&self) -> io::Result<SocketAddr> {
/// # Examples
///
/// ```no_run
/// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpStream};
/// use std::net::{IpAddr, Ipv4Addr, TcpStream};
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// assert_eq!(stream.local_addr().unwrap(),
/// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080)));
/// assert_eq!(stream.local_addr().unwrap().ip(),
/// IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn local_addr(&self) -> io::Result<SocketAddr> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册