// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![unstable(feature = "futures_api", reason = "futures in libcore are unstable", issue = "50547")] /// Indicates whether a value is available or if the current task has been /// scheduled to receive a wakeup instead. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum Poll { /// Represents that a value is immediately ready. Ready(T), /// Represents that a value is not ready yet. /// /// When a function returns `Pending`, the function *must* also /// ensure that the current task is scheduled to be awoken when /// progress can be made. Pending, } impl Poll { /// Change the ready value of this `Poll` with the closure provided pub fn map(self, f: F) -> Poll 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 Poll> { /// Change the success value of this `Poll` with the closure provided pub fn map_ok(self, f: F) -> Poll> 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(self, f: F) -> Poll> 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 From for Poll { fn from(t: T) -> Poll { Poll::Ready(t) } }