blob: d07c04b3ac98c2fc63a175ed83e389267bd84a6c [file] [log] [blame]
#[must_use = "this `Poll` may be a `Pending` variant, which should be handled"]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Poll<T> {
Ready(T),
Pending,
}
impl<T> Poll<T> {
pub fn map<U, F>(self, f: F) -> Poll<U>
where
F: FnOnce(T) -> U,
{
match self {
Poll::Ready(t) => Poll::Ready(f(t)),
Poll::Pending => Poll::Pending,
}
}
#[inline]
pub fn is_ready(&self) -> bool {
match *self {
Poll::Ready(_) => true,
_ => false,
}
}
#[inline]
pub fn is_pending(&self) -> bool {
!self.is_ready()
}
}
impl<T, E> Poll<Result<T, E>> {
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
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,
}
}
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
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<T> From<T> for Poll<T> {
fn from(t: T) -> Poll<T> {
Poll::Ready(t)
}
}