1use std::future::Future;
2use std::pin::Pin;
3use std::task::Context;
4use std::task::Poll;
5
6pub struct BoxFuture<'a, R>(Pin<Box<dyn Future<Output = R> + Send + 'a>>);
8
9impl<'a, R> BoxFuture<'a, R> {
10 pub fn new(f: impl Future<Output = R> + Send + 'a) -> Self {
12 BoxFuture(Box::pin(f))
13 }
14}
15
16impl<'a, R> Future for BoxFuture<'a, R> {
17 type Output = R;
18
19 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
20 Pin::new(&mut self.get_mut().0).poll(cx)
21 }
22}