Skip to content

Commit

Permalink
Remove uses of pin_project::project attribute
Browse files Browse the repository at this point in the history
pin-project will deprecate the project attribute due to some unfixable
limitations.

Refs: taiki-e/pin-project#225
  • Loading branch information
taiki-e authored and zonyitoo committed Jun 6, 2020
1 parent 72a6f13 commit 34f1728
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ lru_time_cache = "0.10"
hyper = { version = "0.13", optional = true }
http = { version = "0.2", optional = true }
tower = { version = "0.3", optional = true }
pin-project = "0.4"
pin-project = "0.4.17"
socket2 = "0.3"
cfg-if = "0.1"
bloomfilter = "^1.0.2"
Expand Down
9 changes: 3 additions & 6 deletions src/relay/tcprelay/http_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::{

use super::ProxyStream;

#[pin_project]
#[pin_project(project = ProxyHttpStreamProj)]
enum ProxyHttpStream {
Http(#[pin] ProxyStream),
#[cfg(feature = "local-http-native-tls")]
Expand Down Expand Up @@ -167,13 +167,10 @@ impl ProxyHttpStream {

macro_rules! forward_call {
($self:expr, $method:ident $(, $param:expr)*) => {
// #[project]
match $self.as_mut().project() {
// ProxyHttpStream::Http(stream) => stream.$method($($param),*),
__ProxyHttpStreamProjection::Http(stream) => stream.$method($($param),*),
ProxyHttpStreamProj::Http(stream) => stream.$method($($param),*),
#[cfg(any(feature = "local-http-native-tls", feature = "local-http-rustls"))]
// ProxyHttpStream::Https(stream, ..) => stream.$method($($param),*),
__ProxyHttpStreamProjection::Https(stream, ..) => stream.$method($($param),*),
ProxyHttpStreamProj::Https(stream, ..) => stream.$method($($param),*),
}
};
}
Expand Down
16 changes: 4 additions & 12 deletions src/relay/tcprelay/proxy_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use bytes::{Buf, BytesMut};
use futures::ready;
use log::{debug, error, trace};
use pin_project::{pin_project, project};
use pin_project::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ReadHalf, WriteHalf};

use crate::{
Expand Down Expand Up @@ -50,7 +50,6 @@ impl ProxiedConnection {
}

impl AsyncRead for ProxiedConnection {
#[project]
fn poll_read(self: Pin<&mut Self>, cx: &mut task::Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
self.project().stream.poll_read(cx, buf)
}
Expand Down Expand Up @@ -163,7 +162,7 @@ impl AsyncWrite for ProxiedConnection {
}
}

#[pin_project]
#[pin_project(project = ProxyConnectionProj)]
enum ProxyConnection {
Direct(#[pin] STcpStream),
Proxied(#[pin] ProxiedConnection),
Expand All @@ -188,36 +187,29 @@ impl ProxyConnection {

macro_rules! forward_call {
($self:expr, $method:ident $(, $param:expr)*) => {
// #[project]
match $self.as_mut().project() {
// ProxyConnection::Direct(stream) => stream.$method($($param),*),
__ProxyConnectionProjection::Direct(stream) => stream.$method($($param),*),
// ProxyConnection::Proxied(stream) => stream.$method($($param),*),
__ProxyConnectionProjection::Proxied(stream) => stream.$method($($param),*),
ProxyConnectionProj::Direct(stream) => stream.$method($($param),*),
ProxyConnectionProj::Proxied(stream) => stream.$method($($param),*),
}
};
}

impl AsyncRead for ProxyConnection {
#[project]
fn poll_read(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
forward_call!(self, poll_read, cx, buf)
}
}

impl AsyncWrite for ProxyConnection {
#[project]
fn poll_write(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
// let p = forward_call!(self, poll_write, cx, buf);
forward_call!(self, poll_write, cx, buf)
}

#[project]
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
forward_call!(self, poll_flush, cx)
}

#[project]
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
forward_call!(self, poll_shutdown, cx)
}
Expand Down

0 comments on commit 34f1728

Please sign in to comment.