Do not require Unpin for some trait impls (#7204)

This commit is contained in:
Alphyr
2025-03-11 08:14:22 +01:00
committed by GitHub
parent e4a39d2ef6
commit 7efcab43c9
5 changed files with 21 additions and 13 deletions
+3 -3
View File
@@ -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);
}
}
+2 -2
View File
@@ -80,7 +80,7 @@ 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(
@@ -88,7 +88,7 @@ where
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)
}
}
+3 -3
View File
@@ -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)
}
}
+5 -5
View File
@@ -224,7 +224,7 @@ 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(
@@ -232,7 +232,7 @@ where
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(
@@ -240,7 +240,7 @@ where
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 {
@@ -248,11 +248,11 @@ where
}
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)
}
}
+8
View File
@@ -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()
}