Skip to content

Commit fb507ca

Browse files
committed
add inherent methods to Poll
1 parent 49eb754 commit fb507ca

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/libcore/task.rs

+49
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,55 @@ pub enum Poll<T> {
3232
Pending,
3333
}
3434

35+
impl<T> Poll<T> {
36+
/// Change the ready value of this `Poll` with the closure provided
37+
pub fn map<U, F>(self, f: F) -> Poll<U>
38+
where F: FnOnce(T) -> U
39+
{
40+
match self {
41+
Poll::Ready(t) => Poll::Ready(f(t)),
42+
Poll::Pending => Poll::Pending,
43+
}
44+
}
45+
46+
/// Returns whether this is `Poll::Ready`
47+
pub fn is_ready(&self) -> bool {
48+
match *self {
49+
Poll::Ready(_) => true,
50+
Poll::Pending => false,
51+
}
52+
}
53+
54+
/// Returns whether this is `Poll::Pending`
55+
pub fn is_pending(&self) -> bool {
56+
!self.is_ready()
57+
}
58+
}
59+
60+
impl<T, E> Poll<Result<T, E>> {
61+
/// Change the success value of this `Poll` with the closure provided
62+
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
63+
where F: FnOnce(T) -> U
64+
{
65+
match self {
66+
Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
67+
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
68+
Poll::Pending => Poll::Pending,
69+
}
70+
}
71+
72+
/// Change the error value of this `Poll` with the closure provided
73+
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
74+
where F: FnOnce(E) -> U
75+
{
76+
match self {
77+
Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
78+
Poll::Ready(Err(e)) => Poll::Ready(Err(f(e))),
79+
Poll::Pending => Poll::Pending,
80+
}
81+
}
82+
}
83+
3584
impl<T> From<T> for Poll<T> {
3685
fn from(t: T) -> Poll<T> {
3786
Poll::Ready(t)

src/libstd/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a, F: Future> Future for AssertUnwindSafe<F> {
327327
let pinned_field = PinMut::new_unchecked(
328328
&mut PinMut::get_mut(self.reborrow()).0
329329
);
330-
330+
331331
pinned_field.poll(cx)
332332
}
333333
}

0 commit comments

Comments
 (0)