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 committed Jun 6, 2020
1 parent 6d9d78e commit 04982cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion noria/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tokio-tower = "0.4"
tracing = "0.1.12"
tracing-futures = "0.2.2"
slab = "0.4"
pin-project = "0.4.0"
pin-project = "0.4.17"
futures-util = "0.3.0"
mysql_common = "0.22"

Expand Down
34 changes: 12 additions & 22 deletions noria/src/channel/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bufstream::BufStream;
use byteorder::{NetworkEndian, WriteBytesExt};
use futures_util::ready;
use futures_util::{sink::Sink, stream::Stream};
use pin_project::{pin_project, project};
use pin_project::pin_project;
use serde::{Deserialize, Serialize};
use std::{
pin::Pin,
Expand Down Expand Up @@ -156,7 +156,7 @@ pub enum RecvError {
DeserializationError(bincode::Error),
}

#[pin_project]
#[pin_project(project = DualTcpStreamProj)]
pub enum DualTcpStream<S, T, T2, D> {
Passthrough(#[pin] AsyncBincodeStream<S, T, Tagged<()>, D>),
Upgrade(
Expand Down Expand Up @@ -194,39 +194,31 @@ where
{
type Error = bincode::Error;

#[project]
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
#[project]
match self.project() {
DualTcpStream::Passthrough(abs) => abs.poll_ready(cx),
DualTcpStream::Upgrade(abs, _) => abs.poll_ready(cx),
DualTcpStreamProj::Passthrough(abs) => abs.poll_ready(cx),
DualTcpStreamProj::Upgrade(abs, _) => abs.poll_ready(cx),
}
}

#[project]
fn start_send(self: Pin<&mut Self>, item: Tagged<()>) -> Result<(), Self::Error> {
#[project]
match self.project() {
DualTcpStream::Passthrough(abs) => abs.start_send(item),
DualTcpStream::Upgrade(abs, _) => abs.start_send(item),
DualTcpStreamProj::Passthrough(abs) => abs.start_send(item),
DualTcpStreamProj::Upgrade(abs, _) => abs.start_send(item),
}
}

#[project]
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
#[project]
match self.project() {
DualTcpStream::Passthrough(abs) => abs.poll_flush(cx),
DualTcpStream::Upgrade(abs, _) => abs.poll_flush(cx),
DualTcpStreamProj::Passthrough(abs) => abs.poll_flush(cx),
DualTcpStreamProj::Upgrade(abs, _) => abs.poll_flush(cx),
}
}

#[project]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
#[project]
match self.project() {
DualTcpStream::Passthrough(abs) => abs.poll_close(cx),
DualTcpStream::Upgrade(abs, _) => abs.poll_close(cx),
DualTcpStreamProj::Passthrough(abs) => abs.poll_close(cx),
DualTcpStreamProj::Upgrade(abs, _) => abs.poll_close(cx),
}
}
}
Expand All @@ -241,14 +233,12 @@ where
{
type Item = Result<T, bincode::Error>;

#[project]
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
// https://github.com/rust-lang/rust-clippy/issues/3071
#[project]
#[allow(clippy::redundant_closure)]
match self.project() {
DualTcpStream::Passthrough(abr) => abr.poll_next(cx),
DualTcpStream::Upgrade(abr, upgrade) => {
DualTcpStreamProj::Passthrough(abr) => abr.poll_next(cx),
DualTcpStreamProj::Upgrade(abr, upgrade) => {
Poll::Ready(ready!(abr.poll_next(cx)).transpose()?.map(upgrade).map(Ok))
}
}
Expand Down

0 comments on commit 04982cc

Please sign in to comment.