Remove pin-project

We always constrain T is Unpin, so we don't need pin-project.
This commit is contained in:
quininer 2019-11-07 23:46:49 +08:00
parent 262796af39
commit 8b3bf3a2b6
2 changed files with 14 additions and 25 deletions

View File

@ -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"

View File

@ -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<IO: AsyncRead + AsyncWrite + Unpin> Future for Accept<IO> {
///
/// 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<T> {
Client(#[pin] client::TlsStream<T>),
Server(#[pin] server::TlsStream<T>),
Client(client::TlsStream<T>),
Server(server::TlsStream<T>),
}
impl<T> TlsStream<T> {
@ -254,17 +252,15 @@ impl<T> AsyncRead for TlsStream<T>
where
T: AsyncRead + AsyncWrite + Unpin,
{
#[project]
#[inline]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
#[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<T> AsyncWrite for TlsStream<T>
where
T: AsyncRead + AsyncWrite + Unpin,
{
#[project]
#[inline]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
#[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<io::Result<()>> {
#[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<io::Result<()>> {
#[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),
}
}
}