Skip to content

Commit

Permalink
chore: Prefer Pin::new over _unpin()
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jun 20, 2024
1 parent 670e8ef commit 4585bd4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
22 changes: 11 additions & 11 deletions iroh-net/src/relay/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ impl Stream for RelayConnReader {

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match *self {
Self::Relay(ref mut ws) => ws.poll_next_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_next_unpin(cx).map(Frame::from_wasm_ws_message),
Self::Relay(ref mut ws) => Pin::new(ws).poll_next(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_next(cx).map(Frame::from_wasm_ws_message),
}
}
}
Expand All @@ -295,31 +295,31 @@ impl Sink<Frame> for RelayConnWriter {

fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Relay(ref mut ws) => ws.poll_ready_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_ready_unpin(cx).map_err(tung_to_io_err),
Self::Relay(ref mut ws) => Pin::new(ws).poll_ready(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_ready(cx).map_err(tung_to_io_err),
}
}

fn start_send(mut self: Pin<&mut Self>, item: Frame) -> Result<(), Self::Error> {
match *self {
Self::Relay(ref mut ws) => ws.start_send_unpin(item),
Self::Ws(ref mut ws) => ws
.start_send_unpin(item.into_wasm_ws_message()?)
Self::Relay(ref mut ws) => Pin::new(ws).start_send(item),
Self::Ws(ref mut ws) => Pin::new(ws)
.start_send(item.into_wasm_ws_message()?)
.map_err(tung_to_io_err),
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Relay(ref mut ws) => ws.poll_flush_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_flush_unpin(cx).map_err(tung_to_io_err),
Self::Relay(ref mut ws) => Pin::new(ws).poll_flush(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_flush(cx).map_err(tung_to_io_err),
}
}

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Relay(ref mut ws) => ws.poll_close_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_close_unpin(cx).map_err(tung_to_io_err),
Self::Relay(ref mut ws) => Pin::new(ws).poll_close(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_close(cx).map_err(tung_to_io_err),
}
}
}
Expand Down
25 changes: 12 additions & 13 deletions iroh-net/src/relay/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::time::Duration;

use anyhow::{bail, Context as _, Result};
use futures_sink::Sink;
use futures_util::sink::SinkExt;
use futures_util::{Stream, StreamExt};
use futures_util::Stream;
use hyper::HeaderMap;
use iroh_metrics::core::UsageStatsReport;
use iroh_metrics::{inc, report_usage_stats};
Expand Down Expand Up @@ -190,31 +189,31 @@ impl Sink<Frame> for RelayIo {

fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Derp(ref mut framed) => framed.poll_ready_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_ready_unpin(cx).map_err(tung_to_io_err),
Self::Derp(ref mut framed) => Pin::new(framed).poll_ready(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_ready(cx).map_err(tung_to_io_err),
}
}

fn start_send(mut self: Pin<&mut Self>, item: Frame) -> Result<(), Self::Error> {
match *self {
Self::Derp(ref mut framed) => framed.start_send_unpin(item),
Self::Ws(ref mut ws) => ws
.start_send_unpin(item.into_ws_message()?)
Self::Derp(ref mut framed) => Pin::new(framed).start_send(item),
Self::Ws(ref mut ws) => Pin::new(ws)
.start_send(item.into_ws_message()?)
.map_err(tung_to_io_err),
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Derp(ref mut framed) => framed.poll_flush_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_flush_unpin(cx).map_err(tung_to_io_err),
Self::Derp(ref mut framed) => Pin::new(framed).poll_flush(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_flush(cx).map_err(tung_to_io_err),
}
}

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
Self::Derp(ref mut framed) => framed.poll_close_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_close_unpin(cx).map_err(tung_to_io_err),
Self::Derp(ref mut framed) => Pin::new(framed).poll_close(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_close(cx).map_err(tung_to_io_err),
}
}
}
Expand All @@ -224,8 +223,8 @@ impl Stream for RelayIo {

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match *self {
Self::Derp(ref mut framed) => framed.poll_next_unpin(cx),
Self::Ws(ref mut ws) => ws.poll_next_unpin(cx).map(Frame::from_ws_message),
Self::Derp(ref mut framed) => Pin::new(framed).poll_next(cx),
Self::Ws(ref mut ws) => Pin::new(ws).poll_next(cx).map(Frame::from_ws_message),
}
}
}
Expand Down

0 comments on commit 4585bd4

Please sign in to comment.