1use std::{
6 future::Future,
7 pin::Pin,
8 task::{Context, Poll},
9};
10
11pin_project_lite::pin_project! {
16 pub struct Fuse<F> {
17 #[pin]
18 inner: Option<F>,
19 }
20}
21
22impl<F> Fuse<F> {
23 pub fn new(future: F) -> Self {
24 Self {
25 inner: Some(future),
26 }
27 }
28}
29
30impl<F> Future for Fuse<F>
31where
32 F: Future,
33{
34 type Output = F::Output;
35
36 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
37 match self.as_mut().project().inner.as_pin_mut() {
38 Some(fut) => fut.poll(cx).map(|output| {
39 self.project().inner.set(None);
40 output
41 }),
42 None => Poll::Pending,
43 }
44 }
45}