From 8b3bf3a2b6c2e4427e2ca6173307e4ec62ca6966 Mon Sep 17 00:00:00 2001 From: quininer Date: Thu, 7 Nov 2019 23:46:49 +0800 Subject: [PATCH] Remove pin-project We always constrain T is Unpin, so we don't need pin-project. --- Cargo.toml | 1 - src/lib.rs | 38 ++++++++++++++------------------------ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f205f6e..d4f3448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ github-actions = { repository = "quininer/tokio-rustls", workflow = "ci" } [dependencies] tokio-io = "=0.2.0-alpha.6" futures-core-preview = "=0.3.0-alpha.19" -pin-project = "0.4" rustls = "0.16" webpki = "0.21" diff --git a/src/lib.rs b/src/lib.rs index d5113e5..8caf1e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ use std::sync::Arc; use std::future::Future; use std::task::{ Context, Poll }; use futures_core as futures; -use pin_project::{ pin_project, project }; use tokio_io::{ AsyncRead, AsyncWrite }; use webpki::DNSNameRef; use rustls::{ ClientConfig, ClientSession, ServerConfig, ServerSession, Session }; @@ -202,10 +201,9 @@ impl Future for Accept { /// /// This abstracts over the inner `client::TlsStream` and `server::TlsStream`, so you can use /// a single type to keep both client- and server-initiated TLS-encrypted connections. -#[pin_project] pub enum TlsStream { - Client(#[pin] client::TlsStream), - Server(#[pin] server::TlsStream), + Client(client::TlsStream), + Server(server::TlsStream), } impl TlsStream { @@ -254,17 +252,15 @@ impl AsyncRead for TlsStream where T: AsyncRead + AsyncWrite + Unpin, { - #[project] #[inline] fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - #[project] - match self.project() { - TlsStream::Client(x) => x.poll_read(cx, buf), - TlsStream::Server(x) => x.poll_read(cx, buf), + match self.get_mut() { + TlsStream::Client(x) => Pin::new(x).poll_read(cx, buf), + TlsStream::Server(x) => Pin::new(x).poll_read(cx, buf), } } } @@ -273,37 +269,31 @@ impl AsyncWrite for TlsStream where T: AsyncRead + AsyncWrite + Unpin, { - #[project] #[inline] fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - #[project] - match self.project() { - TlsStream::Client(x) => x.poll_write(cx, buf), - TlsStream::Server(x) => x.poll_write(cx, buf), + match self.get_mut() { + TlsStream::Client(x) => Pin::new(x).poll_write(cx, buf), + TlsStream::Server(x) => Pin::new(x).poll_write(cx, buf), } } - #[project] #[inline] fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - #[project] - match self.project() { - TlsStream::Client(x) => x.poll_flush(cx), - TlsStream::Server(x) => x.poll_flush(cx), + match self.get_mut() { + TlsStream::Client(x) => Pin::new(x).poll_flush(cx), + TlsStream::Server(x) => Pin::new(x).poll_flush(cx), } } - #[project] #[inline] fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - #[project] - match self.project() { - TlsStream::Client(x) => x.poll_shutdown(cx), - TlsStream::Server(x) => x.poll_shutdown(cx), + match self.get_mut() { + TlsStream::Client(x) => Pin::new(x).poll_shutdown(cx), + TlsStream::Server(x) => Pin::new(x).poll_shutdown(cx), } } }