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

Remove uses of pin_project::project attribute #26

Merged
merged 1 commit into from
Aug 14, 2020
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ futures = "0.3.1"
log = "0.4.8"
nom = "5.0.1"
owning_ref = "0.4.0"
pin-project = "0.4.6"
pin-project = "0.4.17"
rand = "0.7.2"
serde = { version = "1.0.101", features = ["derive"] }
serde_json = "1.0.40"
Expand Down
28 changes: 10 additions & 18 deletions src/tls_or_tcp_stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "tls")]
use native_tls::{self, TlsConnector};
use pin_project::{pin_project, project};
use pin_project::pin_project;
use std::{
pin::Pin,
task::{Context, Poll},
Expand All @@ -13,7 +13,7 @@ use tokio::{
use tokio_tls::{TlsConnector as TokioTlsConnector, TlsStream};

/// A simple wrapper type that can either be a raw TCP stream or a TCP stream with TLS enabled.
#[pin_project]
#[pin_project(project = TlsOrTcpStreamProj)]
#[derive(Debug)]
pub enum TlsOrTcpStream {
TcpStream(#[pin] TcpStream),
Expand Down Expand Up @@ -44,49 +44,41 @@ impl TlsOrTcpStream {
}

impl AsyncRead for TlsOrTcpStream {
#[project]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
#[project]
match self.project() {
TlsOrTcpStream::TcpStream(stream) => stream.poll_read(cx, buf),
TlsOrTcpStreamProj::TcpStream(stream) => stream.poll_read(cx, buf),
#[cfg(feature = "tls")]
TlsOrTcpStream::TlsStream(stream) => stream.poll_read(cx, buf),
TlsOrTcpStreamProj::TlsStream(stream) => stream.poll_read(cx, buf),
}
}
}

impl AsyncWrite for TlsOrTcpStream {
#[project]
fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<io::Result<usize>> {
#[project]
match self.project() {
TlsOrTcpStream::TcpStream(stream) => stream.poll_write(cx, buf),
TlsOrTcpStreamProj::TcpStream(stream) => stream.poll_write(cx, buf),
#[cfg(feature = "tls")]
TlsOrTcpStream::TlsStream(stream) => stream.poll_write(cx, buf),
TlsOrTcpStreamProj::TlsStream(stream) => stream.poll_write(cx, buf),
}
}

#[project]
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
#[project]
match self.project() {
TlsOrTcpStream::TcpStream(stream) => stream.poll_flush(cx),
TlsOrTcpStreamProj::TcpStream(stream) => stream.poll_flush(cx),
#[cfg(feature = "tls")]
TlsOrTcpStream::TlsStream(stream) => stream.poll_flush(cx),
TlsOrTcpStreamProj::TlsStream(stream) => stream.poll_flush(cx),
}
}

#[project]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
#[project]
match self.project() {
TlsOrTcpStream::TcpStream(stream) => stream.poll_shutdown(cx),
TlsOrTcpStreamProj::TcpStream(stream) => stream.poll_shutdown(cx),
#[cfg(feature = "tls")]
TlsOrTcpStream::TlsStream(stream) => stream.poll_shutdown(cx),
TlsOrTcpStreamProj::TlsStream(stream) => stream.poll_shutdown(cx),
}
}
}