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