Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): replace field _pin with !Unpin as argument #2886

Merged
Merged
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
42 changes: 9 additions & 33 deletions core/src/raw/oio/read/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::io;
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
Expand Down Expand Up @@ -187,40 +186,25 @@ impl<T: Read> ReadExt for T {}
pub trait ReadExt: Read {
/// Build a future for `poll_read`.
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> {
ReadFuture {
reader: self,
buf,
_pin: PhantomPinned,
}
ReadFuture { reader: self, buf }
}

/// Build a future for `poll_seek`.
fn seek(&mut self, pos: io::SeekFrom) -> SeekFuture<'_, Self> {
SeekFuture {
reader: self,
pos,
_pin: PhantomPinned,
}
SeekFuture { reader: self, pos }
}

/// Build a future for `poll_next`
fn next(&mut self) -> NextFuture<'_, Self> {
NextFuture {
reader: self,
_pin: PhantomPinned,
}
NextFuture { reader: self }
}
}

#[pin_project]
/// Make this future `!Unpin` for compatibility with async trait methods.
#[pin_project(!Unpin)]
pub struct ReadFuture<'a, R: Read + Unpin + ?Sized> {
reader: &'a mut R,
buf: &'a mut [u8],
/// Make this future `!Unpin` for compatibility with async trait methods.
///
/// Borrowed from tokio.
#[pin]
_pin: PhantomPinned,
}

impl<R> Future for ReadFuture<'_, R>
Expand All @@ -235,15 +219,11 @@ where
}
}

#[pin_project]
/// Make this future `!Unpin` for compatibility with async trait methods.
#[pin_project(!Unpin)]
pub struct SeekFuture<'a, R: Read + Unpin + ?Sized> {
reader: &'a mut R,
pos: io::SeekFrom,
/// Make this future `!Unpin` for compatibility with async trait methods.
///
/// Borrowed from tokio.
#[pin]
_pin: PhantomPinned,
}

impl<R> Future for SeekFuture<'_, R>
Expand All @@ -258,14 +238,10 @@ where
}
}

#[pin_project]
/// Make this future `!Unpin` for compatibility with async trait methods.
#[pin_project(!Unpin)]
pub struct NextFuture<'a, R: Read + Unpin + ?Sized> {
reader: &'a mut R,
/// Make this future `!Unpin` for compatibility with async trait methods.
///
/// Borrowed from tokio.
#[pin]
_pin: PhantomPinned,
}

impl<R> Future for NextFuture<'_, R>
Expand Down