use futures_util::future::Future;
use pin_project::pin_project;
use std::fmt::Debug;
use std::fmt::Display;
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
#[pin_project]
pub struct SendFuture<F> {
#[pin]
inner: F,
}
impl<F> SendFuture<F> {
pub fn new(inner: F) -> Self {
Self { inner }
}
}
unsafe impl<F> Send for SendFuture<F> {}
unsafe impl<F> Sync for SendFuture<F> {}
impl<F: Future> Future for SendFuture<F> {
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.inner.poll(cx)
}
}
pub struct SendWrapper<T>(pub T);
unsafe impl<T> Send for SendWrapper<T> {}
unsafe impl<T> Sync for SendWrapper<T> {}
impl<T> SendWrapper<T> {
pub fn new(inner: T) -> Self {
Self(inner)
}
}
impl<T> std::ops::Deref for SendWrapper<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> std::ops::DerefMut for SendWrapper<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<T: Debug> Debug for SendWrapper<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SendWrapper({:?})", self.0)
}
}
impl<T: Clone> Clone for SendWrapper<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<T: Default> Default for SendWrapper<T> {
fn default() -> Self {
Self(T::default())
}
}
impl<T: Display> Display for SendWrapper<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SendWrapper({})", self.0)
}
}