netstack_smoltcp/
runner.rs1use std::{
2 future::{Future, IntoFuture},
3 pin::Pin,
4 task::{Context, Poll},
5};
6
7pub struct BoxFuture<'a, T>(Pin<Box<dyn Future<Output = T> + 'a>>);
16
17impl<'a, T> BoxFuture<'a, T> {
18 pub fn new<F>(f: F) -> BoxFuture<'a, T>
19 where
20 F: IntoFuture<Output = T> + 'a,
21 {
22 BoxFuture(Box::pin(f.into_future()))
23 }
24
25 #[allow(unused)]
26 pub fn wrap(f: Pin<Box<dyn Future<Output = T> + 'a>>) -> BoxFuture<'a, T> {
27 BoxFuture(f)
28 }
29}
30
31unsafe impl<T: Send> Send for BoxFuture<'_, T> {}
32
33impl<T> Future for BoxFuture<'_, T> {
34 type Output = T;
35
36 fn poll(mut self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> {
37 self.0.as_mut().poll(context)
38 }
39}
40
41pub type Runner = BoxFuture<'static, std::io::Result<()>>;