mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
Do not require Unpin for some trait impls (#7204)
This commit is contained in:
@@ -84,15 +84,15 @@ impl<T: ?Sized + AsyncBufRead + Unpin> AsyncBufRead for &mut T {
|
|||||||
|
|
||||||
impl<P> AsyncBufRead for Pin<P>
|
impl<P> AsyncBufRead for Pin<P>
|
||||||
where
|
where
|
||||||
P: DerefMut + Unpin,
|
P: DerefMut,
|
||||||
P::Target: AsyncBufRead,
|
P::Target: AsyncBufRead,
|
||||||
{
|
{
|
||||||
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
|
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) {
|
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||||
self.get_mut().as_mut().consume(amt);
|
crate::util::pin_as_deref_mut(self).consume(amt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl<T: ?Sized + AsyncRead + Unpin> AsyncRead for &mut T {
|
|||||||
|
|
||||||
impl<P> AsyncRead for Pin<P>
|
impl<P> AsyncRead for Pin<P>
|
||||||
where
|
where
|
||||||
P: DerefMut + Unpin,
|
P: DerefMut,
|
||||||
P::Target: AsyncRead,
|
P::Target: AsyncRead,
|
||||||
{
|
{
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
@@ -88,7 +88,7 @@ where
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
buf: &mut ReadBuf<'_>,
|
buf: &mut ReadBuf<'_>,
|
||||||
) -> Poll<io::Result<()>> {
|
) -> Poll<io::Result<()>> {
|
||||||
self.get_mut().as_mut().poll_read(cx, buf)
|
crate::util::pin_as_deref_mut(self).poll_read(cx, buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,15 +68,15 @@ impl<T: ?Sized + AsyncSeek + Unpin> AsyncSeek for &mut T {
|
|||||||
|
|
||||||
impl<P> AsyncSeek for Pin<P>
|
impl<P> AsyncSeek for Pin<P>
|
||||||
where
|
where
|
||||||
P: DerefMut + Unpin,
|
P: DerefMut,
|
||||||
P::Target: AsyncSeek,
|
P::Target: AsyncSeek,
|
||||||
{
|
{
|
||||||
fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> io::Result<()> {
|
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>> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ impl<T: ?Sized + AsyncWrite + Unpin> AsyncWrite for &mut T {
|
|||||||
|
|
||||||
impl<P> AsyncWrite for Pin<P>
|
impl<P> AsyncWrite for Pin<P>
|
||||||
where
|
where
|
||||||
P: DerefMut + Unpin,
|
P: DerefMut,
|
||||||
P::Target: AsyncWrite,
|
P::Target: AsyncWrite,
|
||||||
{
|
{
|
||||||
fn poll_write(
|
fn poll_write(
|
||||||
@@ -232,7 +232,7 @@ where
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
buf: &[u8],
|
buf: &[u8],
|
||||||
) -> Poll<io::Result<usize>> {
|
) -> 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(
|
fn poll_write_vectored(
|
||||||
@@ -240,7 +240,7 @@ where
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
bufs: &[IoSlice<'_>],
|
bufs: &[IoSlice<'_>],
|
||||||
) -> Poll<io::Result<usize>> {
|
) -> 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 {
|
fn is_write_vectored(&self) -> bool {
|
||||||
@@ -248,11 +248,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
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<()>> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,3 +96,11 @@ pub(crate) mod cacheline;
|
|||||||
cfg_io_driver_impl! {
|
cfg_io_driver_impl! {
|
||||||
pub(crate) mod ptr_expose;
|
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()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user