rune/shared/
assert_send.rs

1use core::future::Future;
2use core::pin::Pin;
3use core::task::{Context, Poll};
4
5/// Internal helper struct to assert that a future is send.
6#[pin_project::pin_project]
7pub(crate) struct AssertSend<T>(#[pin] T);
8
9impl<T> AssertSend<T> {
10    /// Assert that the given inner value is `Send` by some external invariant.
11    ///
12    /// # Safety
13    ///
14    /// ProtocolCaller must assert that nothing is done with inner that violates it
15    /// being `Send` at runtime.
16    pub(crate) unsafe fn new(inner: T) -> Self {
17        Self(inner)
18    }
19}
20
21// Safety: we wrap all APIs around the [VmExecution], preventing values from
22// escaping from contained virtual machine.
23unsafe impl<T> Send for AssertSend<T> {}
24
25impl<T> Future for AssertSend<T>
26where
27    T: Future,
28{
29    type Output = T::Output;
30
31    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
32        let this = self.project();
33        this.0.poll(cx)
34    }
35}