From fe2b9976755407b85c82b5cdee9d8c5e16e3d6c6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 27 Oct 2020 09:30:29 +0100 Subject: util: upgrade tokio-util to bytes 0.6 (#3052) --- tokio-util/src/io/read_buf.rs | 65 ------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 tokio-util/src/io/read_buf.rs (limited to 'tokio-util/src/io/read_buf.rs') diff --git a/tokio-util/src/io/read_buf.rs b/tokio-util/src/io/read_buf.rs deleted file mode 100644 index d617fa6f..00000000 --- a/tokio-util/src/io/read_buf.rs +++ /dev/null @@ -1,65 +0,0 @@ -use bytes::BufMut; -use std::future::Future; -use std::io; -use std::pin::Pin; -use std::task::{Context, Poll}; -use tokio::io::AsyncRead; - -/// Read data from an `AsyncRead` into an implementer of the [`Buf`] trait. -/// -/// [`Buf`]: bytes::Buf -/// -/// # Example -/// -/// ``` -/// use bytes::{Bytes, BytesMut}; -/// use tokio::stream; -/// use tokio::io::Result; -/// use tokio_util::io::{StreamReader, read_buf}; -/// # #[tokio::main] -/// # async fn main() -> std::io::Result<()> { -/// -/// // Create a reader from an iterator. This particular reader will always be -/// // ready. -/// let mut read = StreamReader::new(stream::iter(vec![Result::Ok(Bytes::from_static(&[0, 1, 2, 3]))])); -/// -/// let mut buf = BytesMut::new(); -/// let mut reads = 0; -/// -/// loop { -/// reads += 1; -/// let n = read_buf(&mut read, &mut buf).await?; -/// -/// if n == 0 { -/// break; -/// } -/// } -/// -/// // one or more reads might be necessary. -/// assert!(reads >= 1); -/// assert_eq!(&buf[..], &[0, 1, 2, 3]); -/// # Ok(()) -/// # } -/// ``` -pub async fn read_buf(read: &mut R, buf: &mut B) -> io::Result -where - R: AsyncRead + Unpin, - B: BufMut, -{ - return ReadBufFn(read, buf).await; - - struct ReadBufFn<'a, R, B>(&'a mut R, &'a mut B); - - impl<'a, R, B> Future for ReadBufFn<'a, R, B> - where - R: AsyncRead + Unpin, - B: BufMut, - { - type Output = io::Result; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = &mut *self; - super::poll_read_buf(Pin::new(this.0), cx, this.1) - } - } -} -- cgit v1.2.3