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

Don't require Unpin when pin projecting. #89

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/stream.rs
Expand Up @@ -18,7 +18,7 @@ pub enum Stream<S, T> {
Tls(#[pin] T),
}

impl<S: AsyncRead + Unpin, T: AsyncRead + Unpin> AsyncRead for Stream<S, T> {
impl<S: AsyncRead, T: AsyncRead> AsyncRead for Stream<S, T> {
#[project]
fn poll_read(
self: Pin<&mut Self>,
Expand All @@ -27,13 +27,13 @@ impl<S: AsyncRead + Unpin, T: AsyncRead + Unpin> AsyncRead for Stream<S, T> {
) -> Poll<std::io::Result<usize>> {
#[project]
match self.project() {
Stream::Plain(ref mut s) => Pin::new(s).poll_read(cx, buf),
Stream::Tls(ref mut s) => Pin::new(s).poll_read(cx, buf),
Stream::Plain(s) => s.poll_read(cx, buf),
Stream::Tls(s) => s.poll_read(cx, buf),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I do enjoy a bit simpler code here, I also find your thoughts on #90 reasonable, so I would probably prefer the approach from #90.

}
}
}

impl<S: AsyncWrite + Unpin, T: AsyncWrite + Unpin> AsyncWrite for Stream<S, T> {
impl<S: AsyncWrite, T: AsyncWrite> AsyncWrite for Stream<S, T> {
#[project]
fn poll_write(
self: Pin<&mut Self>,
Expand All @@ -42,17 +42,17 @@ impl<S: AsyncWrite + Unpin, T: AsyncWrite + Unpin> AsyncWrite for Stream<S, T> {
) -> Poll<Result<usize, std::io::Error>> {
#[project]
match self.project() {
Stream::Plain(ref mut s) => Pin::new(s).poll_write(cx, buf),
Stream::Tls(ref mut s) => Pin::new(s).poll_write(cx, buf),
Stream::Plain(s) => s.poll_write(cx, buf),
Stream::Tls(s) => s.poll_write(cx, buf),
}
}

#[project]
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
#[project]
match self.project() {
Stream::Plain(ref mut s) => Pin::new(s).poll_flush(cx),
Stream::Tls(ref mut s) => Pin::new(s).poll_flush(cx),
Stream::Plain(s) => s.poll_flush(cx),
Stream::Tls(s) => s.poll_flush(cx),
}
}

Expand All @@ -63,8 +63,8 @@ impl<S: AsyncWrite + Unpin, T: AsyncWrite + Unpin> AsyncWrite for Stream<S, T> {
) -> Poll<Result<(), std::io::Error>> {
#[project]
match self.project() {
Stream::Plain(ref mut s) => Pin::new(s).poll_shutdown(cx),
Stream::Tls(ref mut s) => Pin::new(s).poll_shutdown(cx),
Stream::Plain(s) => s.poll_shutdown(cx),
Stream::Tls(s) => s.poll_shutdown(cx),
}
}
}