|  | 
|  | 1 | +use crate::future::Future; | 
|  | 2 | +use crate::marker; | 
|  | 3 | +use crate::pin::Pin; | 
|  | 4 | +use crate::task::{Context, Poll}; | 
|  | 5 | + | 
|  | 6 | +/// Creates a future which never resolves, representing a computation that never | 
|  | 7 | +/// finishes. | 
|  | 8 | +/// | 
|  | 9 | +/// This `struct` is created by the [`pending`] function. See its | 
|  | 10 | +/// documentation for more. | 
|  | 11 | +/// | 
|  | 12 | +/// [`pending`]: fn.pending.html | 
|  | 13 | +#[unstable(feature = "future_readiness_fns", issue = "70921")] | 
|  | 14 | +#[derive(Debug)] | 
|  | 15 | +#[must_use = "futures do nothing unless you `.await` or poll them"] | 
|  | 16 | +pub struct Pending<T> { | 
|  | 17 | +    _data: marker::PhantomData<T>, | 
|  | 18 | +} | 
|  | 19 | + | 
|  | 20 | +/// Creates a future which never resolves, representing a computation that never | 
|  | 21 | +/// finishes. | 
|  | 22 | +/// | 
|  | 23 | +/// # Examples | 
|  | 24 | +/// | 
|  | 25 | +/// ```no_run | 
|  | 26 | +/// #![feature(future_readiness_fns)] | 
|  | 27 | +/// use core::future; | 
|  | 28 | +/// | 
|  | 29 | +/// # async fn run() { | 
|  | 30 | +/// let future = future::pending(); | 
|  | 31 | +/// let () = future.await; | 
|  | 32 | +/// unreachable!(); | 
|  | 33 | +/// # } | 
|  | 34 | +/// ``` | 
|  | 35 | +#[unstable(feature = "future_readiness_fns", issue = "70921")] | 
|  | 36 | +pub fn pending<T>() -> Pending<T> { | 
|  | 37 | +    Pending { _data: marker::PhantomData } | 
|  | 38 | +} | 
|  | 39 | + | 
|  | 40 | +#[unstable(feature = "future_readiness_fns", issue = "70921")] | 
|  | 41 | +impl<T> Future for Pending<T> { | 
|  | 42 | +    type Output = T; | 
|  | 43 | + | 
|  | 44 | +    fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { | 
|  | 45 | +        Poll::Pending | 
|  | 46 | +    } | 
|  | 47 | +} | 
|  | 48 | + | 
|  | 49 | +#[unstable(feature = "future_readiness_fns", issue = "70921")] | 
|  | 50 | +impl<T> Unpin for Pending<T> {} | 
|  | 51 | + | 
|  | 52 | +#[unstable(feature = "future_readiness_fns", issue = "70921")] | 
|  | 53 | +impl<T> Clone for Pending<T> { | 
|  | 54 | +    fn clone(&self) -> Self { | 
|  | 55 | +        pending() | 
|  | 56 | +    } | 
|  | 57 | +} | 
0 commit comments