1use core::pin::Pin;
2use futures_core::future::{FusedFuture, Future, TryFuture};
3use futures_core::task::{Context, Poll};
4use pin_project_lite::pin_project;
5
6pin_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
16impl<Fut> IntoFuture<Fut> {
17 #[inline]
18 pub(crate) fn new(future: Fut) -> Self {
19 Self { future }
20 }
21}
22
23impl<Fut: TryFuture + FusedFuture> FusedFuture for IntoFuture<Fut> {
24 fn is_terminated(&self) -> bool {
25 self.future.is_terminated()
26 }
27}
28
29impl<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}
37