Skip to main content

fast_down_gui/utils/
force_send.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5pub struct ForceSend<F>(pub F);
6
7unsafe impl<F> Send for ForceSend<F> {}
8
9impl<F: Future> Future for ForceSend<F> {
10    type Output = F::Output;
11    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
12        unsafe { self.map_unchecked_mut(|s| &mut s.0).poll(cx) }
13    }
14}
15
16pub trait ForceSendExt {
17    fn force_send(self) -> ForceSend<Self>
18    where
19        Self: Sized,
20    {
21        ForceSend(self)
22    }
23}
24
25impl<F> ForceSendExt for F {
26    fn force_send(self) -> ForceSend<Self> {
27        ForceSend(self)
28    }
29}