tls_api/
future.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::task::Context;
4use std::task::Poll;
5
6/// Newtype for `Pin<Box<Future>>` for simpler function signatures.
7pub struct BoxFuture<'a, R>(Pin<Box<dyn Future<Output = R> + Send + 'a>>);
8
9impl<'a, R> BoxFuture<'a, R> {
10    /// Wrap a future.
11    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}