Skip to main content

Polling

Enum Polling 

Source
pub enum Polling<Fut: Future> {
    Ready(Fut::Output),
    Pending(Fut),
    Done,
}
Expand description

An enum similar to Poll, but containing a future in its Pending variant.

§Example

use futures_lite::future;
use futures_polling::{FuturePollingExt, Polling};

let mut polling = async {
    future::yield_now().await;
    42
}.polling();

assert_eq!(polling.is_pending(), true);

// Poll just once.
polling.polling_once().await;
assert_eq!(polling.is_pending(), true);

// Poll until the inner future is ready.
assert_eq!(polling.await, 42);

Variants§

§

Ready(Fut::Output)

Contains the future’s output once it has returned it (like Poll::Ready).

§Example
use futures_polling::{FuturePollingExt, Polling};

let mut polling = async { 42i32 }.polling();
polling.polling_once().await;

if let Polling::Ready(out) = polling {
    assert_eq!(out, 42);
} else {
    unreachable!();
}

// or

assert_eq!(polling.into_ready(), Some(42));
§

Pending(Fut)

Contains the pending future.

§Example
use futures_lite::future;
use futures_polling::{FuturePollingExt, Polling};

let mut polling = async {
    future::yield_now().await;
    42i32
}.polling();

if let Polling::Pending(_) = polling {
    // -> future::yield_now().await;
    polling.polling_once().await;
} else {
    unreachable!();
}

if let Polling::Pending(_) = polling {
    // 42
    polling.polling_once().await;
} else {
    unreachable!();
}

assert_eq!(polling.into_ready(), Some(42));
§

Done

The future has already returned an output, but it has already been extracted out of Polling.

§Example
use futures_polling::{FuturePollingExt, Polling};

let mut polling = async { 42i32 }.polling();
polling.polling_once().await;

assert_eq!(polling.take_ready(), Some(42));
assert_eq!(polling.is_done(), true);

Implementations§

Source§

impl<Fut: Future> Polling<Fut>

Source

pub fn into_ready(self) -> Option<Fut::Output>

selfreturn
Polling::Ready(out)Some(out)
Polling::Pending(_)None
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.into_ready(), Some(42));

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.into_ready(), None);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.into_ready(), None);
Source

pub fn into_pending(self) -> Option<Fut>

selfreturn
Polling::Ready(_)None
Polling::Pending(fut)Some(fut)
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.into_pending().is_some(), false);

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.into_pending().unwrap().await, 42);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.into_pending().is_some(), false);
Source

pub fn into_poll(self) -> Poll<Fut::Output>

selfreturn
Polling::Ready(out)Poll::Ready(out)
Polling::Pending(_)Poll::Pending
Polling::DonePoll::Pending
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.into_poll(), Poll::Ready(42));

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.into_poll(), Poll::Pending);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.into_poll(), Poll::Pending);
Source

pub fn is_ready(&self) -> bool

Returns true is self is Polling::Ready(_).

§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.is_ready(), true);

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.is_ready(), false);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.is_ready(), false);
Source

pub fn is_pending(&self) -> bool

Returns true is self is Polling::Pending(_).

§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.is_pending(), false);

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.is_pending(), true);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.is_pending(), false);
Source

pub fn is_done(&self) -> bool

Returns true is self is Polling::Done.

§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.is_done(), false);

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.is_done(), false);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.is_done(), true);
Source

pub fn as_ready(&self) -> Option<&Fut::Output>

&selfreturn
Polling::Ready(out)Some(&out)
Polling::Pending(_)None
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.as_ready(), Some(&42));

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_ready(), None);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_ready(), None);
Source

pub fn as_pending(&self) -> Option<&Fut>

&selfreturn
Polling::Ready(_)None
Polling::Pending(fut)Some(&fut)
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.as_pending().is_some(), false);

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_pending().is_some(), true);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_pending().is_some(), false);
Source

pub fn as_poll(&self) -> Poll<&Fut::Output>

&selfreturn
Polling::Ready(out)Poll::Ready(&out)
Polling::Pending(_)Poll::Pending
Polling::DonePoll::Pending
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.as_poll(), Poll::Ready(&42));

let polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_poll(), Poll::Pending);

let polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_poll(), Poll::Pending);
Source

pub fn as_ready_mut(&mut self) -> Option<&mut Fut::Output>

&mut selfreturn
Polling::Ready(out)Some(&mut out)
Polling::Pending(_)None
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
if let Some(out) = polling.as_ready_mut() {
    assert_eq!(*out, 42);
    *out = 0;
} else {
    unreachable!();
}
assert_eq!(polling.as_ready(), Some(&0));

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_ready_mut(), None);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_ready_mut(), None);
Source

pub fn as_pending_mut(&mut self) -> Option<&mut Fut>

&mut selfreturn
Polling::Ready(_)None
Polling::Pending(fut)Some(&mut fut)
Polling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.as_pending_mut().is_some(), false);

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_pending_mut().unwrap().await, 42);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_pending_mut().is_some(), false);
Source

pub fn as_poll_mut(&mut self) -> Poll<&mut Fut::Output>

&mut selfreturn
Polling::Ready(out)Poll::Ready(&mut out)
Polling::Pending(_)Poll::Pending
Polling::DonePoll::Pending
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
if let Poll::Ready(out) = polling.as_poll_mut() {
    *out = 0;
} else {
    unreachable!();
}
assert_eq!(polling.as_poll(), Poll::Ready(&0));

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.as_poll_mut(), Poll::Pending);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.as_poll_mut(), Poll::Pending);
Source

pub fn replace(&mut self, with: Self) -> Self

Moves with into &mut self and returns the previous self.

§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut p1 = Polling::<Ready<i32>>::Ready(42);
let p2 = Polling::<Ready<i32>>::Ready(24);

let p3 = p1.replace(p2);

assert_eq!(p1.as_ready(), Some(&24));
assert_eq!(p3.as_ready(), Some(&42));
Source

pub fn take(&mut self) -> Polling<Fut>

Takes the output or future out of self, leaving Polling::Done in its place.

§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.take().into_ready(), Some(42));
assert_eq!(polling.into_ready(), None);

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.take().into_pending().unwrap().await, 42);
assert_eq!(polling.into_pending().is_some(), false);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.take().is_done(), true);
assert_eq!(polling.is_done(), true);
Source

pub fn take_ready(&mut self) -> Option<Fut::Output>

&mut selfnew self valuereturn
Polling::Ready(out)Polling::DoneSome(out)
Polling::Pending(fut)Polling::Pending(fut)None
Polling::DonePolling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.take_ready(), Some(42));
assert_eq!(polling.into_ready(), None);

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.take_ready(), None);
assert_eq!(polling.into_pending().unwrap().await, 42);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.take_ready(), None);
assert_eq!(polling.is_done(), true);
Source

pub fn take_pending(&mut self) -> Option<Fut>

&mut selfnew self valuereturn
Polling::Ready(out)Polling::Ready(out)None
Polling::Pending(fut)Polling::DoneSome(fut)
Polling::DonePolling::DoneNone
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.take_pending().is_some(), false);
assert_eq!(polling.into_ready(), Some(42));

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.take_pending().unwrap().await, 42);
assert_eq!(polling.into_pending().is_some(), false);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.take_pending().is_some(), false);
assert_eq!(polling.is_done(), true);
Source

pub fn take_poll(&mut self) -> Poll<Fut::Output>

&mut selfnew self valuereturn
Polling::Ready(out)Polling::DonePoll::Ready(out)
Polling::Pending(fut)Polling::Pending(fut)Poll::Pending
Polling::DonePolling::DonePoll::Pending
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.take_poll(), Poll::Ready(42));
assert_eq!(polling.into_ready(), None);

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.take_poll(), Poll::Pending);
assert_eq!(polling.into_pending().unwrap().await, 42);

let mut polling = Polling::<Ready<i32>>::Done;
assert_eq!(polling.take_poll(), Poll::Pending);
assert_eq!(polling.is_done(), true);
Source

pub async fn poll_once(&mut self) -> Poll<Fut::Output>

&mut selffut.poll(_)new self valuereturn
Polling::Ready(out)xPolling::DonePoll::Ready(out)
Polling::Pending(fut)Poll::Ready(out)Polling::DonePoll::Ready(out)
Polling::Pending(fut)Poll::PendingPolling::Pending(fut)Poll::Pending
Polling::Donexpanic!()panic!()
§Example
use core::task::Poll;
use futures_lite::future::{self, Pending, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
assert_eq!(polling.poll_once().await, Poll::Ready(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
assert_eq!(polling.poll_once().await, Poll::Ready(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Pending<i32>>::Pending(future::pending());
assert_eq!(polling.poll_once().await, Poll::Pending);
assert_eq!(polling.is_done(), false);
Source

pub async fn polling_once(&mut self) -> &mut Self

&mut selffut.poll(_)new self value
Polling::Ready(out)xPolling::Ready(out)
Polling::Pending(fut)Poll::Ready(out)Polling::Ready(out)
Polling::Pending(fut)Poll::PendingPolling::Pending(fut)
Polling::Donexpanic!()
§Example
use core::task::Poll;
use futures_lite::future::{self, Pending, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<i32>>::Ready(42);
polling.polling_once().await;
assert_eq!(polling.take_poll(), Poll::Ready(42));

let mut polling = Polling::<Ready<i32>>::Pending(future::ready(42));
polling.polling_once().await;
assert_eq!(polling.take_poll(), Poll::Ready(42));

let mut polling = Polling::<Pending<i32>>::Pending(future::pending());
polling.polling_once().await;
assert_eq!(polling.is_pending(), true);
Source§

impl<T, E, Fut: Future<Output = Result<T, E>>> Polling<Fut>

Source

pub fn try_into_ready(self) -> Result<Option<T>, E>

selfreturn
Polling::Ready(Ok(ok))Ok(Some(ok))
Polling::Ready(Err(err))Err(err)
Polling::Pending(_)Ok(None)
Polling::DoneOk(None)
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_into_ready(), Ok(Some(42)));

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_into_ready(), Err(42));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_into_ready(), Ok(None));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_into_ready(), Ok(None));

let polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_into_ready(), Ok(None));
Source

pub fn try_into_poll(self) -> Result<Poll<T>, E>

selfreturn
Polling::Ready(Ok(ok))Ok(Poll::Ready(ok))
Polling::Ready(Err(err))Err(err)
Polling::Pending(_)Ok(Poll::Pending)
Polling::DoneOk(Poll::Pending)
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_into_poll(), Ok(Poll::Ready(42)));

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_into_poll(), Err(42));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_into_poll(), Ok(Poll::Pending));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_into_poll(), Ok(Poll::Pending));

let polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_into_poll(), Ok(Poll::Pending));
Source

pub fn try_as_ready(&self) -> Result<Option<&T>, &E>

&selfreturn
Polling::Ready(Ok(ok))Ok(Some(&ok))
Polling::Ready(Err(Err))Err(&err)
Polling::Pending(_)Ok(None)
Polling::DoneOk(None)
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_as_ready(), Ok(Some(&42)));

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_as_ready(), Err(&42));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_as_ready(), Ok(None));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_as_ready(), Ok(None));

let polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_as_ready(), Ok(None));
Source

pub fn try_as_poll(&self) -> Result<Poll<&T>, &E>

&selfreturn
Polling::Ready(Ok(ok))Ok(Poll::Ready(&ok))
Polling::Ready(Err(Err))Err(&mut err)
Polling::Pending(_)Ok(Poll::Pending)
Polling::DoneOk(Poll::Pending)
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_as_poll(), Ok(Poll::Ready(&42)));

let polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_as_poll(), Err(&42));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_as_poll(), Ok(Poll::Pending));

let polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_as_poll(), Ok(Poll::Pending));

let polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_as_poll(), Ok(Poll::Pending));
Source

pub fn try_as_ready_mut(&mut self) -> Result<Option<&mut T>, &mut E>

&mut selfreturn
Polling::Ready(Ok(ok))Ok(Some(&mut ok))
Polling::Ready(Err(Err))Err(&mut err)
Polling::Pending(_)Ok(None)
Polling::DoneOk(None)
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
if let Ok(Some(ok)) = polling.try_as_ready_mut() {
    assert_eq!(*ok, 42);
    *ok = 0;
} else {
    unreachable!();
}
assert_eq!(polling.try_as_ready(), Ok(Some(&0)));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
if let Err(err) = polling.try_as_ready_mut() {
    assert_eq!(*err, 42);
    *err = 0;
} else {
    unreachable!();
}
assert_eq!(polling.try_as_ready(), Err(&0));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_as_ready_mut(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_as_ready_mut(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_as_ready_mut(), Ok(None));
Source

pub fn try_as_poll_mut(&mut self) -> Result<Poll<&mut T>, &mut E>

&mut selfreturn
Polling::Ready(Ok(ok))Ok(Poll::Ready(&mut ok))
Polling::Ready(Err(Err))Err(&mut err)
Polling::Pending(_)Ok(Poll::Pending)
Polling::DoneOk(Poll::Pending)
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
if let Ok(Poll::Ready(ok)) = polling.try_as_poll_mut() {
    assert_eq!(*ok, 42);
    *ok = 0;
} else {
    unreachable!();
}
assert_eq!(polling.try_as_poll(), Ok(Poll::Ready(&0)));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
if let Err(err) = polling.try_as_poll_mut() {
    assert_eq!(*err, 42);
    *err = 0;
} else {
    unreachable!();
}
assert_eq!(polling.try_as_poll(), Err(&0));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_as_poll_mut(), Ok(Poll::Pending));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_as_poll_mut(), Ok(Poll::Pending));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_as_poll_mut(), Ok(Poll::Pending));
Source

pub fn try_take_ready(&mut self) -> Result<Option<T>, E>

&mut selfnew self valuereturn
Polling::Ready(Ok(ok))Polling::DoneOk(Some(ok))
Polling::Ready(Err(err))Polling::DoneErr(err)
Polling::Pending(fut)Polling::Pending(fut)Ok(None)
Polling::DonePolling::DoneOk(None)
§Example
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_take_ready(), Ok(Some(42)));
assert_eq!(polling.try_into_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_take_ready(), Err(42));
assert_eq!(polling.try_into_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_take_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_take_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_take_ready(), Ok(None));
Source

pub fn try_take_poll(&mut self) -> Result<Poll<T>, E>

&mut selfnew self valuereturn
Polling::Ready(Ok(ok))Polling::DoneOk(Poll::Ready(ok))
Polling::Ready(Err(err))Polling::DoneErr(err)
Polling::Pending(fut)Polling::Pending(fut)Ok(Poll::Pending)
Polling::DonePolling::DoneOk(Poll::Pending)
§Example
use core::task::Poll;
use futures_lite::future::{self, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_take_poll(), Ok(Poll::Ready(42)));
assert_eq!(polling.try_into_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_take_poll(), Err(42));
assert_eq!(polling.try_into_ready(), Ok(None));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_take_poll(), Ok(Poll::Pending));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_take_poll(), Ok(Poll::Pending));

let mut polling = Polling::<Ready<Result<i32, i32>>>::Done;
assert_eq!(polling.try_take_poll(), Ok(Poll::Pending));
Source

pub fn try_poll( self: Pin<&mut Self>, ctx: &mut Context<'_>, ) -> Result<Poll<T>, E>

&mut selffut.poll(ctx)new self valuereturn
Polling::Ready(Ok(ok))xPolling::DoneOk(Poll:Ready(ok))
Polling::Ready(Err(err))xPolling::DoneErr(err)
Polling::Pending(fut)Poll::Ready(Ok(ok))Polling::DoneOk(Poll::Ready(ok))
Polling::Pending(fut)Poll::Ready(Err(err))Polling::DoneErr(err)
Polling::Pending(fut)Poll::PendingPolling::Pending(fut)Ok(Poll::Pending)
Polling::Donexpanic!()panic!()
§Example
use core::pin::Pin;
use core::task::Poll;
use futures_lite::future::{self, Pending, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(Pin::new(&mut polling).try_poll(ctx), Ok(Poll::Ready(42)));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(Pin::new(&mut polling).try_poll(ctx), Err(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(Pin::new(&mut polling).try_poll(ctx), Ok(Poll::Ready(42)));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(Pin::new(&mut polling).try_poll(ctx), Err(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Pending<Result<i32, i32>>>::Pending(future::pending());
assert_eq!(Pin::new(&mut polling).try_poll(ctx), Ok(Poll::Pending));
assert_eq!(polling.is_done(), false);
Source

pub async fn try_poll_once(&mut self) -> Result<Poll<T>, E>

&mut selffut.poll(_)new self valuereturn
Polling::Ready(Ok(ok))xPolling::DoneOk(Poll:Ready(ok))
Polling::Ready(Err(err))xPolling::DoneErr(err)
Polling::Pending(fut)Poll::Ready(Ok(ok))Polling::DoneOk(Poll::Ready(ok))
Polling::Pending(fut)Poll::Ready(Err(err))Polling::DoneErr(err)
Polling::Pending(fut)Poll::PendingPolling::Pending(fut)Ok(Poll::Pending)
Polling::Donexpanic!()panic!()
§Example
use core::task::Poll;
use futures_lite::future::{self, Pending, Ready};
use futures_polling::Polling;

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Ok(42));
assert_eq!(polling.try_poll_once().await, Ok(Poll::Ready(42)));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Ready(Err(42));
assert_eq!(polling.try_poll_once().await, Err(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Ok(42)));
assert_eq!(polling.try_poll_once().await, Ok(Poll::Ready(42)));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Ready<Result<i32, i32>>>::Pending(future::ready(Err(42)));
assert_eq!(polling.try_poll_once().await, Err(42));
assert_eq!(polling.is_done(), true);

let mut polling = Polling::<Pending<Result<i32, i32>>>::Pending(future::pending());
assert_eq!(polling.try_poll_once().await, Ok(Poll::Pending));
assert_eq!(polling.is_done(), false);

Trait Implementations§

Source§

impl<Fut: Clone + Future> Clone for Polling<Fut>
where Fut::Output: Clone,

Source§

fn clone(&self) -> Polling<Fut>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Fut: Debug + Future> Debug for Polling<Fut>
where Fut::Output: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Fut: Future> From<Fut> for Polling<Fut>

Source§

fn from(fut: Fut) -> Self

Converts to this type from the input type.
Source§

impl<Fut: Future> Future for Polling<Fut>

Source§

type Output = <Fut as Future>::Output

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<Fut: Hash + Future> Hash for Polling<Fut>
where Fut::Output: Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Fut: Ord + Future> Ord for Polling<Fut>
where Fut::Output: Ord,

Source§

fn cmp(&self, other: &Polling<Fut>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Fut: PartialEq + Future> PartialEq for Polling<Fut>
where Fut::Output: PartialEq,

Source§

fn eq(&self, other: &Polling<Fut>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Fut: PartialOrd + Future> PartialOrd for Polling<Fut>
where Fut::Output: PartialOrd,

Source§

fn partial_cmp(&self, other: &Polling<Fut>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Fut: Copy + Future> Copy for Polling<Fut>
where Fut::Output: Copy,

Source§

impl<Fut: Eq + Future> Eq for Polling<Fut>
where Fut::Output: Eq,

Source§

impl<Fut: Future> StructuralPartialEq for Polling<Fut>

Auto Trait Implementations§

§

impl<Fut> Freeze for Polling<Fut>
where <Fut as Future>::Output: Freeze, Fut: Freeze,

§

impl<Fut> RefUnwindSafe for Polling<Fut>
where <Fut as Future>::Output: RefUnwindSafe, Fut: RefUnwindSafe,

§

impl<Fut> Send for Polling<Fut>
where <Fut as Future>::Output: Send, Fut: Send,

§

impl<Fut> Sync for Polling<Fut>
where <Fut as Future>::Output: Sync, Fut: Sync,

§

impl<Fut> Unpin for Polling<Fut>
where <Fut as Future>::Output: Unpin, Fut: Unpin,

§

impl<Fut> UnsafeUnpin for Polling<Fut>
where <Fut as Future>::Output: UnsafeUnpin, Fut: UnsafeUnpin,

§

impl<Fut> UnwindSafe for Polling<Fut>
where <Fut as Future>::Output: UnwindSafe, Fut: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<Fut> FuturePollingExt for Fut
where Fut: Future,

Source§

fn polling(self) -> Polling<Self>
where Self: Sized,

Returns [Polling::Pending(self)], consuming self. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.