summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/util/read_buf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/io/util/read_buf.rs')
-rw-r--r--tokio/src/io/util/read_buf.rs57
1 files changed, 23 insertions, 34 deletions
diff --git a/tokio/src/io/util/read_buf.rs b/tokio/src/io/util/read_buf.rs
index 7df429d7..696deefd 100644
--- a/tokio/src/io/util/read_buf.rs
+++ b/tokio/src/io/util/read_buf.rs
@@ -40,44 +40,33 @@ where
type Output = io::Result<usize>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
- let mut me = self.project();
- poll_read_buf(&mut me.reader, &mut me.buf, cx)
- }
-}
+ use crate::io::ReadBuf;
+ use std::mem::MaybeUninit;
-pub(crate) fn poll_read_buf<'a, R, B>(
- reader: &'a mut R,
- buf: &'a mut B,
- cx: &mut Context<'_>,
-) -> Poll<io::Result<usize>>
-where
- R: AsyncRead + Unpin,
- B: BufMut,
-{
- use crate::io::ReadBuf;
- use std::mem::MaybeUninit;
+ let me = self.project();
- if !buf.has_remaining_mut() {
- return Poll::Ready(Ok(0));
- }
+ if !me.buf.has_remaining_mut() {
+ return Poll::Ready(Ok(0));
+ }
- let n = {
- let dst = buf.bytes_mut();
- let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) };
- let mut buf = ReadBuf::uninit(dst);
- let ptr = buf.filled().as_ptr();
- ready!(Pin::new(reader).poll_read(cx, &mut buf)?);
+ let n = {
+ let dst = me.buf.bytes_mut();
+ let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) };
+ let mut buf = ReadBuf::uninit(dst);
+ let ptr = buf.filled().as_ptr();
+ ready!(Pin::new(me.reader).poll_read(cx, &mut buf)?);
- // Ensure the pointer does not change from under us
- assert_eq!(ptr, buf.filled().as_ptr());
- buf.filled().len()
- };
+ // Ensure the pointer does not change from under us
+ assert_eq!(ptr, buf.filled().as_ptr());
+ buf.filled().len()
+ };
- // Safety: This is guaranteed to be the number of initialized (and read)
- // bytes due to the invariants provided by `ReadBuf::filled`.
- unsafe {
- buf.advance_mut(n);
- }
+ // Safety: This is guaranteed to be the number of initialized (and read)
+ // bytes due to the invariants provided by `ReadBuf::filled`.
+ unsafe {
+ me.buf.advance_mut(n);
+ }
- Poll::Ready(Ok(n))
+ Poll::Ready(Ok(n))
+ }
}