use std::pin::Pin;
use crate::{
AsyncClose,
AsyncOutput,
CloseFuture,
FlushFuture,
WriteFullyFuture,
WriteFuture,
};
pub trait PinnedAsyncOutputExt {
type Output: AsyncOutput + ?Sized;
fn write_async<'a>(
&'a mut self,
input: &'a [<Self::Output as AsyncOutput>::Item],
) -> WriteFuture<'a, Self::Output>;
fn write_fully_async<'a>(
&'a mut self,
input: &'a [<Self::Output as AsyncOutput>::Item],
) -> WriteFullyFuture<'a, Self::Output>;
fn flush_async(&mut self) -> FlushFuture<'_, Self::Output>;
fn close_async(&mut self) -> CloseFuture<'_, Self::Output>
where
Self::Output: AsyncClose;
}
impl<O> PinnedAsyncOutputExt for Pin<&mut O>
where
O: AsyncOutput + ?Sized,
{
type Output = O;
#[inline(always)]
fn write_async<'a>(
&'a mut self,
input: &'a [O::Item],
) -> WriteFuture<'a, Self::Output> {
WriteFuture::new(self.as_mut(), input)
}
#[inline(always)]
fn write_fully_async<'a>(
&'a mut self,
input: &'a [O::Item],
) -> WriteFullyFuture<'a, Self::Output> {
WriteFullyFuture::new(self.as_mut(), input)
}
#[inline(always)]
fn flush_async(&mut self) -> FlushFuture<'_, Self::Output> {
FlushFuture::new(self.as_mut())
}
#[inline(always)]
fn close_async(&mut self) -> CloseFuture<'_, Self::Output>
where
Self::Output: AsyncClose,
{
CloseFuture::new(self.as_mut())
}
}