1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
pub struct DynFuture<T> {
inner: Pin<Box<dyn Future<Output = T> + Send>>,
}
impl<T> DynFuture<T> {
pub fn new(f: impl Future<Output = T> + Send + 'static) -> Self {
Self { inner: Box::pin(f) }
}
}
impl<T> Future for DynFuture<T> {
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
self.get_mut().inner.as_mut().poll(cx)
}
}