Debian Codegraph @

third_party/rust/futures-util/src/future/try_future/into_future.rs

raw
1 use core::pin::Pin;
2 use futures_core::future::{FusedFuture, Future, TryFuture};
3 use futures_core::task::{Context, Poll};
4 use pin_project_lite::pin_project;
5
6 pin_project! {
7 /// Future for the [`into_future`](super::TryFutureExt::into_future) method.
8 #[derive(Debug)]
9 #[must_use = "futures do nothing unless you `.await` or poll them"]
10 pub struct IntoFuture<Fut> {
11 #[pin]
12 future: Fut,
13 }
14 }
15
16 impl<Fut> IntoFuture<Fut> {
17 #[inline]
18 pub(crate) fn new(future: Fut) -> Self {
19 Self { future }
20 }
21 }
22
23 impl<Fut: TryFuture + FusedFuture> FusedFuture for IntoFuture<Fut> {
24 fn is_terminated(&self) -> bool {
25 self.future.is_terminated()
26 }
27 }
28
29 impl<Fut: TryFuture> Future for IntoFuture<Fut> {
30 type Output = Result<Fut::Ok, Fut::Error>;
31
32 #[inline]
33 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
34 self.project().future.try_poll(cx)
35 }
36 }