Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions tokio/src/io/async_buf_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ impl<T: ?Sized + AsyncBufRead + Unpin> AsyncBufRead for &mut T {

impl<P> AsyncBufRead for Pin<P>
where
P: DerefMut + Unpin,
P: DerefMut,
P::Target: AsyncBufRead,
{
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
self.get_mut().as_mut().poll_fill_buf(cx)
crate::util::pin_as_deref_mut(self).poll_fill_buf(cx)
}

fn consume(self: Pin<&mut Self>, amt: usize) {
self.get_mut().as_mut().consume(amt);
crate::util::pin_as_deref_mut(self).consume(amt);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl<T: ?Sized + AsyncRead + Unpin> AsyncRead for &mut T {

impl<P> AsyncRead for Pin<P>
where
P: DerefMut + Unpin,
P: DerefMut,
P::Target: AsyncRead,
{
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
self.get_mut().as_mut().poll_read(cx, buf)
crate::util::pin_as_deref_mut(self).poll_read(cx, buf)
}
}

Expand Down
6 changes: 3 additions & 3 deletions tokio/src/io/async_seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl<T: ?Sized + AsyncSeek + Unpin> AsyncSeek for &mut T {

impl<P> AsyncSeek for Pin<P>
where
P: DerefMut + Unpin,
P: DerefMut,
P::Target: AsyncSeek,
{
fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> io::Result<()> {
self.get_mut().as_mut().start_seek(pos)
crate::util::pin_as_deref_mut(self).start_seek(pos)
}

fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
self.get_mut().as_mut().poll_complete(cx)
crate::util::pin_as_deref_mut(self).poll_complete(cx)
}
}

Expand Down
10 changes: 5 additions & 5 deletions tokio/src/io/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,35 +224,35 @@ impl<T: ?Sized + AsyncWrite + Unpin> AsyncWrite for &mut T {

impl<P> AsyncWrite for Pin<P>
where
P: DerefMut + Unpin,
P: DerefMut,
P::Target: AsyncWrite,
{
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.get_mut().as_mut().poll_write(cx, buf)
crate::util::pin_as_deref_mut(self).poll_write(cx, buf)
}

fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<io::Result<usize>> {
self.get_mut().as_mut().poll_write_vectored(cx, bufs)
crate::util::pin_as_deref_mut(self).poll_write_vectored(cx, bufs)
}

fn is_write_vectored(&self) -> bool {
(**self).is_write_vectored()
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
self.get_mut().as_mut().poll_flush(cx)
crate::util::pin_as_deref_mut(self).poll_flush(cx)
}

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
self.get_mut().as_mut().poll_shutdown(cx)
crate::util::pin_as_deref_mut(self).poll_shutdown(cx)
}
}

Expand Down
8 changes: 8 additions & 0 deletions tokio/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ pub(crate) mod cacheline;
cfg_io_driver_impl! {
pub(crate) mod ptr_expose;
}

use std::{ops::DerefMut, pin::Pin};

/// Copy of [`std::pin::Pin::as_deref_mut`].
// TODO: Remove this once we bump the MSRV to 1.84.
pub(crate) fn pin_as_deref_mut<P: DerefMut>(ptr: Pin<&mut Pin<P>>) -> Pin<&mut P::Target> {
unsafe { ptr.get_unchecked_mut() }.as_mut()
}