Files
tokio/tokio-udp/src/recv.rs
T

31 lines
807 B
Rust
Raw Normal View History

2019-06-27 02:41:36 +08:00
use super::UdpSocket;
use std::future::Future;
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
/// A future that receives a datagram from the connected address.
///
/// This `struct` is created by [`recv`](super::UdpSocket::recv).
#[must_use = "futures do nothing unless you `.await` or poll them"]
2019-06-27 02:41:36 +08:00
#[derive(Debug)]
pub struct Recv<'a, 'b> {
2019-07-09 05:47:31 +08:00
socket: &'a UdpSocket,
2019-06-27 02:41:36 +08:00
buf: &'b mut [u8],
}
impl<'a, 'b> Recv<'a, 'b> {
2019-07-09 05:47:31 +08:00
pub(super) fn new(socket: &'a UdpSocket, buf: &'b mut [u8]) -> Self {
2019-06-27 02:41:36 +08:00
Self { socket, buf }
}
}
impl<'a, 'b> Future for Recv<'a, 'b> {
type Output = io::Result<usize>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let Recv { socket, buf } = self.get_mut();
2019-07-09 05:47:31 +08:00
socket.poll_recv_priv(cx, buf)
2019-06-27 02:41:36 +08:00
}
}