Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PollExt trait #625

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,3 @@ pub use crate::share::{FlowControl, Ping, PingPong, Pong, RecvStream, SendStream

#[cfg(feature = "unstable")]
pub use codec::{Codec, SendError, UserError};

use std::task::Poll;

// TODO: Get rid of this trait once https://github.com/rust-lang/rust/pull/63512
// is stabilized.
trait PollExt<T, E> {
/// Changes the success value of this `Poll` with the closure provided.
fn map_ok_<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
where
F: FnOnce(T) -> U;
/// Changes the error value of this `Poll` with the closure provided.
fn map_err_<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
where
F: FnOnce(E) -> U;
}

impl<T, E> PollExt<T, E> for Poll<Option<Result<T, E>>> {
fn map_ok_<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
where
F: FnOnce(T) -> U,
{
match self {
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(f(t)))),
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
Poll::Ready(None) => Poll::Ready(None),
Poll::Pending => Poll::Pending,
}
}

fn map_err_<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
where
F: FnOnce(E) -> U,
{
match self {
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(t))),
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(f(e)))),
Poll::Ready(None) => Poll::Ready(None),
Poll::Pending => Poll::Pending,
}
}
}
3 changes: 1 addition & 2 deletions src/proto/streams/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use http::{HeaderMap, Request, Response};
use std::task::{Context, Poll, Waker};
use tokio::io::AsyncWrite;

use crate::PollExt;
use std::sync::{Arc, Mutex};
use std::{fmt, io};

Expand Down Expand Up @@ -1282,7 +1281,7 @@ impl OpaqueStreamRef {
me.actions
.recv
.poll_pushed(cx, &mut stream)
.map_ok_(|(h, key)| {
.map_ok(|(h, key)| {
me.refs += 1;
let opaque_ref =
OpaqueStreamRef::new(self.inner.clone(), &mut me.store.resolve(key));
Expand Down
7 changes: 3 additions & 4 deletions src/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::proto::{self, WindowSize};
use bytes::{Buf, Bytes};
use http::HeaderMap;

use crate::PollExt;
use std::fmt;
#[cfg(feature = "stream")]
use std::pin::Pin;
Expand Down Expand Up @@ -307,8 +306,8 @@ impl<B: Buf> SendStream<B> {
pub fn poll_capacity(&mut self, cx: &mut Context) -> Poll<Option<Result<usize, crate::Error>>> {
self.inner
.poll_capacity(cx)
.map_ok_(|w| w as usize)
.map_err_(Into::into)
.map_ok(|w| w as usize)
.map_err(Into::into)
}

/// Sends a single data frame to the remote peer.
Expand Down Expand Up @@ -403,7 +402,7 @@ impl RecvStream {

/// Poll for the next data frame.
pub fn poll_data(&mut self, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, crate::Error>>> {
self.inner.inner.poll_data(cx).map_err_(Into::into)
self.inner.inner.poll_data(cx).map_err(Into::into)
}

#[doc(hidden)]
Expand Down