Skip to content

Commit 84cab92

Browse files
committed
Provide map_ok and map_err method for Poll<Option<Result<T, E>>>
1 parent 60960a2 commit 84cab92

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/libcore/task/poll.rs

+28
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,34 @@ impl<T, E> Poll<Result<T, E>> {
8181
}
8282
}
8383

84+
impl<T, E> Poll<Option<Result<T, E>>> {
85+
/// Changes the success value of this `Poll` with the closure provided.
86+
#[unstable(feature = "poll_map", issue = "63514")]
87+
pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
88+
where F: FnOnce(T) -> U
89+
{
90+
match self {
91+
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(f(t)))),
92+
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
93+
Poll::Ready(None) => Poll::Ready(None),
94+
Poll::Pending => Poll::Pending,
95+
}
96+
}
97+
98+
/// Changes the error value of this `Poll` with the closure provided.
99+
#[unstable(feature = "poll_map", issue = "63514")]
100+
pub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
101+
where F: FnOnce(E) -> U
102+
{
103+
match self {
104+
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(t))),
105+
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(f(e)))),
106+
Poll::Ready(None) => Poll::Ready(None),
107+
Poll::Pending => Poll::Pending,
108+
}
109+
}
110+
}
111+
84112
#[stable(feature = "futures_api", since = "1.36.0")]
85113
impl<T> From<T> for Poll<T> {
86114
fn from(t: T) -> Poll<T> {

0 commit comments

Comments
 (0)