Document UdpSocket peer_addr NotConnected error

This commit is contained in:
Linus Unnebäck 2019-03-12 11:19:33 +00:00
parent bf473e3c15
commit 24e3fa079c
No known key found for this signature in database
GPG key ID: CE70CEAE9C0FA66F

View file

@ -193,6 +193,19 @@ impl UdpSocket {
/// assert_eq!(socket.peer_addr().unwrap(),
/// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203)));
/// ```
///
/// If the socket isn't connected, it will return a [`NotConnected`] error.
///
/// [`NotConnected`]: ../../std/io/enum.ErrorKind.html#variant.NotConnected
///
/// ```no_run
/// #![feature(udp_peer_addr)]
/// use std::net::UdpSocket;
///
/// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address");
/// assert_eq!(socket.peer_addr().unwrap_err().kind(),
/// ::std::io::ErrorKind::NotConnected);
/// ```
#[unstable(feature = "udp_peer_addr", issue = "59127")]
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
self.0.peer_addr()