2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-03-31 13:36:41 +00:00

Merge pull request #671 from Noah-Kennedy/udp-socket-send-doc

Fix docs for UdpSocket::send
This commit is contained in:
nasa 2020-01-15 10:41:04 +09:00 committed by GitHub
commit 1071e82132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -244,9 +244,12 @@ impl UdpSocket {
})) }))
} }
/// Sends data on the socket to the given address. /// Sends data on the socket to the remote address to which it is connected.
/// ///
/// On success, returns the number of bytes written. /// The [`connect`] method will connect this socket to a remote address.
/// This method will fail if the socket is not connected.
///
/// [`connect`]: #method.connect
/// ///
/// # Examples /// # Examples
/// ///
@ -255,18 +258,11 @@ impl UdpSocket {
/// # /// #
/// use async_std::net::UdpSocket; /// use async_std::net::UdpSocket;
/// ///
/// const THE_MERCHANT_OF_VENICE: &[u8] = b" /// let socket = UdpSocket::bind("127.0.0.1:34254").await?;
/// If you prick us, do we not bleed? /// socket.connect("127.0.0.1:8080").await?;
/// If you tickle us, do we not laugh? /// let bytes = socket.send(b"Hi there!").await?;
/// If you poison us, do we not die?
/// And if you wrong us, shall we not revenge?
/// ";
/// ///
/// let socket = UdpSocket::bind("127.0.0.1:0").await?; /// println!("Sent {} bytes", bytes);
///
/// let addr = "127.0.0.1:7878";
/// let sent = socket.send_to(THE_MERCHANT_OF_VENICE, &addr).await?;
/// println!("Sent {} bytes to {}", sent, addr);
/// # /// #
/// # Ok(()) }) } /// # Ok(()) }) }
/// ``` /// ```