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] new(future: Fut) -> Self18 pub(crate) fn new(future: Fut) -> Self { 19 Self { future } 20 } 21 } 22 23 impl<Fut: TryFuture + FusedFuture> FusedFuture for IntoFuture<Fut> { is_terminated(&self) -> bool24 fn is_terminated(&self) -> bool { self.future.is_terminated() } 25 } 26 27 impl<Fut: TryFuture> Future for IntoFuture<Fut> { 28 type Output = Result<Fut::Ok, Fut::Error>; 29 30 #[inline] poll( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Self::Output>31 fn poll( 32 self: Pin<&mut Self>, 33 cx: &mut Context<'_>, 34 ) -> Poll<Self::Output> { 35 self.project().future.try_poll(cx) 36 } 37 } 38