Replace internal PollExt trait with Poll inherent methods (#625)
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
41
src/lib.rs
41
src/lib.rs
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user