1 #![unstable(feature = "futures_api",
2 reason = "futures in libcore are unstable",
8 /// Indicates whether a value is available or if the current task has been
9 /// scheduled to receive a wakeup instead.
10 #[must_use = "this `Poll` may be a `Pending` variant, which should be handled"]
11 #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13 /// Represents that a value is immediately ready.
16 /// Represents that a value is not ready yet.
18 /// When a function returns `Pending`, the function *must* also
19 /// ensure that the current task is scheduled to be awoken when
20 /// progress can be made.
25 /// Changes the ready value of this `Poll` with the closure provided.
26 pub fn map<U, F>(self, f: F) -> Poll<U>
27 where F: FnOnce(T) -> U
30 Poll::Ready(t) => Poll::Ready(f(t)),
31 Poll::Pending => Poll::Pending,
35 /// Returns `true` if this is `Poll::Ready`
37 pub fn is_ready(&self) -> bool {
39 Poll::Ready(_) => true,
40 Poll::Pending => false,
44 /// Returns `true` if this is `Poll::Pending`
46 pub fn is_pending(&self) -> bool {
51 impl<T, E> Poll<Result<T, E>> {
52 /// Changes the success value of this `Poll` with the closure provided.
53 pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
54 where F: FnOnce(T) -> U
57 Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
58 Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
59 Poll::Pending => Poll::Pending,
63 /// Changes the error value of this `Poll` with the closure provided.
64 pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
65 where F: FnOnce(E) -> U
68 Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
69 Poll::Ready(Err(e)) => Poll::Ready(Err(f(e))),
70 Poll::Pending => Poll::Pending,
75 impl<T> From<T> for Poll<T> {
76 fn from(t: T) -> Poll<T> {
81 impl<T, E> Try for Poll<Result<T, E>> {
86 fn into_result(self) -> Result<Self::Ok, Self::Error> {
88 Poll::Ready(Ok(x)) => Ok(Poll::Ready(x)),
89 Poll::Ready(Err(e)) => Err(e),
90 Poll::Pending => Ok(Poll::Pending),
95 fn from_error(e: Self::Error) -> Self {
100 fn from_ok(x: Self::Ok) -> Self {
105 impl<T, E> Try for Poll<Option<Result<T, E>>> {
106 type Ok = Poll<Option<T>>;
110 fn into_result(self) -> Result<Self::Ok, Self::Error> {
112 Poll::Ready(Some(Ok(x))) => Ok(Poll::Ready(Some(x))),
113 Poll::Ready(Some(Err(e))) => Err(e),
114 Poll::Ready(None) => Ok(Poll::Ready(None)),
115 Poll::Pending => Ok(Poll::Pending),
120 fn from_error(e: Self::Error) -> Self {
121 Poll::Ready(Some(Err(e)))
125 fn from_ok(x: Self::Ok) -> Self {