Skip to content

Commit

Permalink
Remove PollExt trait
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
  • Loading branch information
kckeiks committed Jul 18, 2022
1 parent fd4040d commit b059583
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
41 changes: 0 additions & 41 deletions src/lib.rs
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
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
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

0 comments on commit b059583

Please sign in to comment.