use super::Feed;
use super::Sink;
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Send<'a, Si: ?Sized, Item> {
feed: Feed<'a, Si, Item>,
}
impl<Si: ?Sized, Item> Unpin for Send<'_, Si, Item> {}
impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Send<'a, Si, Item> {
pub(super) fn new(sink: &'a mut Si, item: Item) -> Self {
Self {
feed: Feed::new(sink, item),
}
}
}
impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Send<'_, Si, Item> {
type Output = Result<(), Si::Error>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut();
if this.feed.is_item_pending() {
match Pin::new(&mut this.feed).poll(cx) {
Poll::Ready(Ok(())) => {
debug_assert!(!this.feed.is_item_pending());
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
}
}
this.feed.sink_pin_mut().poll_flush(cx)
}
}