add inherent methods to Poll
This commit is contained in:
parent
49eb754cc0
commit
fb507cadf3
2 changed files with 50 additions and 1 deletions
|
@ -32,6 +32,55 @@ pub enum Poll<T> {
|
||||||
Pending,
|
Pending,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Poll<T> {
|
||||||
|
/// Change the ready value of this `Poll` with the closure provided
|
||||||
|
pub fn map<U, F>(self, f: F) -> Poll<U>
|
||||||
|
where F: FnOnce(T) -> U
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Poll::Ready(t) => Poll::Ready(f(t)),
|
||||||
|
Poll::Pending => Poll::Pending,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is `Poll::Ready`
|
||||||
|
pub fn is_ready(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
Poll::Ready(_) => true,
|
||||||
|
Poll::Pending => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is `Poll::Pending`
|
||||||
|
pub fn is_pending(&self) -> bool {
|
||||||
|
!self.is_ready()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> Poll<Result<T, E>> {
|
||||||
|
/// Change the success value of this `Poll` with the closure provided
|
||||||
|
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
|
||||||
|
where F: FnOnce(T) -> U
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
|
||||||
|
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
|
||||||
|
Poll::Pending => Poll::Pending,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Change the error value of this `Poll` with the closure provided
|
||||||
|
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
|
||||||
|
where F: FnOnce(E) -> U
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
|
||||||
|
Poll::Ready(Err(e)) => Poll::Ready(Err(f(e))),
|
||||||
|
Poll::Pending => Poll::Pending,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> From<T> for Poll<T> {
|
impl<T> From<T> for Poll<T> {
|
||||||
fn from(t: T) -> Poll<T> {
|
fn from(t: T) -> Poll<T> {
|
||||||
Poll::Ready(t)
|
Poll::Ready(t)
|
||||||
|
|
|
@ -327,7 +327,7 @@ impl<'a, F: Future> Future for AssertUnwindSafe<F> {
|
||||||
let pinned_field = PinMut::new_unchecked(
|
let pinned_field = PinMut::new_unchecked(
|
||||||
&mut PinMut::get_mut(self.reborrow()).0
|
&mut PinMut::get_mut(self.reborrow()).0
|
||||||
);
|
);
|
||||||
|
|
||||||
pinned_field.poll(cx)
|
pinned_field.poll(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue