/rust/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.21/src/future/pending.rs
Line | Count | Source |
1 | | use super::assert_future; |
2 | | use core::marker; |
3 | | use core::pin::Pin; |
4 | | use futures_core::future::{FusedFuture, Future}; |
5 | | use futures_core::task::{Context, Poll}; |
6 | | |
7 | | /// Future for the [`pending()`] function. |
8 | | #[derive(Debug)] |
9 | | #[must_use = "futures do nothing unless you `.await` or poll them"] |
10 | | pub struct Pending<T> { |
11 | | _data: marker::PhantomData<T>, |
12 | | } |
13 | | |
14 | | impl<T> FusedFuture for Pending<T> { |
15 | 0 | fn is_terminated(&self) -> bool { |
16 | 0 | true |
17 | 0 | } |
18 | | } |
19 | | |
20 | | /// Creates a future which never resolves, representing a computation that never |
21 | | /// finishes. |
22 | | /// |
23 | | /// The returned future will forever return [`Poll::Pending`]. |
24 | | /// |
25 | | /// # Examples |
26 | | /// |
27 | | /// ```ignore |
28 | | /// # futures::executor::block_on(async { |
29 | | /// use futures::future; |
30 | | /// |
31 | | /// let future = future::pending(); |
32 | | /// let () = future.await; |
33 | | /// unreachable!(); |
34 | | /// # }); |
35 | | /// ``` |
36 | 500 | pub fn pending<T>() -> Pending<T> { |
37 | 500 | assert_future::<T, _>(Pending { _data: marker::PhantomData }) |
38 | 500 | } futures_util::future::pending::pending::<()> Line | Count | Source | 36 | 500 | pub fn pending<T>() -> Pending<T> { | 37 | 500 | assert_future::<T, _>(Pending { _data: marker::PhantomData }) | 38 | 500 | } |
Unexecuted instantiation: futures_util::future::pending::pending::<_> |
39 | | |
40 | | impl<T> Future for Pending<T> { |
41 | | type Output = T; |
42 | | |
43 | 608 | fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { |
44 | 608 | Poll::Pending |
45 | 608 | } <futures_util::future::pending::Pending<()> as core::future::future::Future>::poll Line | Count | Source | 43 | 608 | fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> { | 44 | 608 | Poll::Pending | 45 | 608 | } |
Unexecuted instantiation: <futures_util::future::pending::Pending<_> as core::future::future::Future>::poll |
46 | | } |
47 | | |
48 | | impl<T> Unpin for Pending<T> {} |
49 | | |
50 | | impl<T> Clone for Pending<T> { |
51 | 0 | fn clone(&self) -> Self { |
52 | 0 | pending() |
53 | 0 | } |
54 | | } |