diff options
| author | Gurwinder Singh <vargwin@gmail.com> | 2019-08-13 13:18:48 +0530 |
|---|---|---|
| committer | Gurwinder Singh <vargwin@gmail.com> | 2019-08-13 15:15:33 +0530 |
| commit | 84cab928db8526af7c42e1637e7253a009da215d (patch) | |
| tree | d41971252b5561fc830f7e81472722d60e83e24f /src/libcore/task | |
| parent | 60960a260f7b5c695fd0717311d72ce62dd4eb43 (diff) | |
| download | rust-84cab928db8526af7c42e1637e7253a009da215d.tar.gz rust-84cab928db8526af7c42e1637e7253a009da215d.zip | |
Provide map_ok and map_err method for Poll<Option<Result<T, E>>>
Diffstat (limited to 'src/libcore/task')
| -rw-r--r-- | src/libcore/task/poll.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/task/poll.rs b/src/libcore/task/poll.rs index 3db70d5e764..fec17c4d1a4 100644 --- a/src/libcore/task/poll.rs +++ b/src/libcore/task/poll.rs @@ -81,6 +81,34 @@ impl<T, E> Poll<Result<T, E>> { } } +impl<T, E> Poll<Option<Result<T, E>>> { + /// Changes the success value of this `Poll` with the closure provided. + #[unstable(feature = "poll_map", issue = "63514")] + pub 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, + } + } + + /// Changes the error value of this `Poll` with the closure provided. + #[unstable(feature = "poll_map", issue = "63514")] + pub 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, + } + } +} + #[stable(feature = "futures_api", since = "1.36.0")] impl<T> From<T> for Poll<T> { fn from(t: T) -> Poll<T> { |
