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