pub trait AsyncRecvFrom: DatagramSocketTypes {
// Required method
fn poll_recv_from(
self: Pin<&Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<(usize, Self::SocketAddr, Option<Self::SocketAddr>), Self::Error>>;
// Provided method
fn next_recv_from<'a, 'b>(
&'a self,
buf: &'b mut [u8],
) -> NextRecvFromFuture<'a, 'b, Self> ⓘ { ... }
}
Expand description
Trait for providing recv_from
functionality for asynchronous, datagram-based sockets.
The value returned on success is a tuple of the following:
(bytes_written: usize,
remote_socket_addr: SocketAddr,
local_socket_addr: Option<SocketAddr>)
local_socket_addr
indicates the local address that the packet was sent to, and may not be
supported. If this isn’t supported, local_socket_addr
will be set to None
.
Required Methods§
Sourcefn poll_recv_from(
self: Pin<&Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<(usize, Self::SocketAddr, Option<Self::SocketAddr>), Self::Error>>
fn poll_recv_from( self: Pin<&Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<(usize, Self::SocketAddr, Option<Self::SocketAddr>), Self::Error>>
A non-blocking1, poll_*
version of std::net::UdpSocket::recv_from
that can
optionally provide the destination (local) SocketAddr
.
If you need to receive a packet from within an async block, see
AsyncRecvFrom::next_recv_from
, which returns a Future
.
Note that while the spirit of this method intends for it to be non-blocking,
AllowStdUdpSocket
can in fact block execution depending on the state of the underlyingstd::net::UdpSocket
. ↩
Provided Methods§
Sourcefn next_recv_from<'a, 'b>(
&'a self,
buf: &'b mut [u8],
) -> NextRecvFromFuture<'a, 'b, Self> ⓘ
fn next_recv_from<'a, 'b>( &'a self, buf: &'b mut [u8], ) -> NextRecvFromFuture<'a, 'b, Self> ⓘ
Returns a future that uses poll_recv_from
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.