//! Utilities for working with [`Future`]s.1use core::{2future::Future,3pin::pin,4task::{Context, Poll, Waker},5};67/// Consumes a future, polls it once, and immediately returns the output8/// or returns `None` if it wasn't ready yet.9///10/// This will cancel the future if it's not ready.11pub fn now_or_never<F: Future>(future: F) -> Option<F::Output> {12let mut cx = Context::from_waker(Waker::noop());13match pin!(future).poll(&mut cx) {14Poll::Ready(x) => Some(x),15_ => None,16}17}1819/// Polls a future once, and returns the output if ready20/// or returns `None` if it wasn't ready yet.21pub fn check_ready<F: Future + Unpin>(future: &mut F) -> Option<F::Output> {22now_or_never(future)23}242526