Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udp: add into_parts to RecvDgram #710

Merged
merged 7 commits into from
Nov 15, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tokio-udp/src/recv_dgram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ impl<T> RecvDgram<T> {
let inner = RecvDgramInner { socket: socket, buffer: buffer };
RecvDgram { state: Some(inner) }
}

/// Consume the `RecvDgram`, returning the socket and buffer.
///
/// ```
/// # extern crate tokio_udp;
///
/// use tokio_udp::UdpSocket;
///
/// # pub fn main() {
///
/// let socket = UdpSocket::bind(&([127, 0, 0, 1], 0).into()).unwrap();
/// let mut buffer = vec![0; 4096];
///
/// let future = socket.recv_dgram(buffer);
///
/// // ... polling `future` ... giving up (e.g. after timeout)
///
/// let (socket, buffer) = future.into_parts();
///
/// # }
/// ```
/// # Panics
///
/// If called after the future has completed.
pub fn into_parts(mut self) -> (UdpSocket, T) {
let state = self.state
.take()
.expect("into_parts called after completion");
(state.socket, state.buffer)
}
}

impl<T> Future for RecvDgram<T>
Expand Down