summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/util/read_until.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/io/util/read_until.rs')
-rw-r--r--tokio/src/io/util/read_until.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/tokio/src/io/util/read_until.rs b/tokio/src/io/util/read_until.rs
index 78dac8c2..3599cff3 100644
--- a/tokio/src/io/util/read_until.rs
+++ b/tokio/src/io/util/read_until.rs
@@ -1,12 +1,14 @@
use crate::io::AsyncBufRead;
+use pin_project_lite::pin_project;
use std::future::Future;
use std::io;
+use std::marker::PhantomPinned;
use std::mem;
use std::pin::Pin;
use std::task::{Context, Poll};
-cfg_io_util! {
+pin_project! {
/// Future for the [`read_until`](crate::io::AsyncBufReadExt::read_until) method.
/// The delimeter is included in the resulting vector.
#[derive(Debug)]
@@ -15,9 +17,12 @@ cfg_io_util! {
reader: &'a mut R,
delimeter: u8,
buf: &'a mut Vec<u8>,
- /// The number of bytes appended to buf. This can be less than buf.len() if
- /// the buffer was not empty when the operation was started.
+ // The number of bytes appended to buf. This can be less than buf.len() if
+ // the buffer was not empty when the operation was started.
read: usize,
+ // Make this future `!Unpin` for compatibility with async trait methods.
+ #[pin]
+ _pin: PhantomPinned,
}
}
@@ -34,6 +39,7 @@ where
delimeter,
buf,
read: 0,
+ _pin: PhantomPinned,
}
}
@@ -66,24 +72,8 @@ pub(super) fn read_until_internal<R: AsyncBufRead + ?Sized>(
impl<R: AsyncBufRead + ?Sized + Unpin> Future for ReadUntil<'_, R> {
type Output = io::Result<usize>;
- fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
- let Self {
- reader,
- delimeter,
- buf,
- read,
- } = &mut *self;
- read_until_internal(Pin::new(reader), cx, *delimeter, buf, read)
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn assert_unpin() {
- use std::marker::PhantomPinned;
- crate::is_unpin::<ReadUntil<'_, PhantomPinned>>();
+ fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
+ let me = self.project();
+ read_until_internal(Pin::new(*me.reader), cx, *me.delimeter, me.buf, me.read)
}
}