use futures::Stream;
#[cfg(feature = "send_wrapper")]
pub use send_wrapper::SendWrapper;
#[cfg(not(feature = "send_wrapper"))]
pub use noop_wrapper::NoopWrapper as SendWrapper;
#[cfg(not(feature = "send_wrapper"))]
mod noop_wrapper {
use std::{
pin::Pin,
task::{Context, Poll},
};
use futures::{Future, Stream};
use pin_project::pin_project;
#[pin_project]
pub struct NoopWrapper<T> {
#[pin]
item: T,
}
impl<T> Future for NoopWrapper<T>
where
T: Future,
{
type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.item.poll(cx)
}
}
impl<T> Stream for NoopWrapper<T>
where
T: Stream,
{
type Item = T::Item;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.project();
this.item.poll_next(cx)
}
}
impl<T> NoopWrapper<T> {
pub fn new(item: T) -> Self {
Self { item }
}
}
}
pub trait IntoSendFuture {
type Output;
fn into_send(self) -> Self::Output;
}
impl<T> IntoSendFuture for T
where
T: futures::Future,
{
type Output = SendWrapper<T>;
fn into_send(self) -> Self::Output {
SendWrapper::new(self)
}
}
pub trait IntoSendStream {
type Output;
fn into_send(self) -> Self::Output;
}
impl<T> IntoSendStream for T
where
T: Stream,
{
type Output = SendWrapper<T>;
fn into_send(self) -> Self::Output {
SendWrapper::new(self)
}
}