use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
use crate::AsyncInput;
#[must_use]
#[repr(transparent)]
pub struct BoxAsyncInput<I>
where
I: AsyncInput + ?Sized,
{
inner: Pin<Box<I>>,
}
impl<I> BoxAsyncInput<I>
where
I: AsyncInput + ?Sized,
{
#[inline(always)]
pub fn new(inner: Box<I>) -> Self {
Self {
inner: Box::into_pin(inner),
}
}
#[inline(always)]
#[must_use]
pub fn get_ref(&self) -> &I {
self.inner.as_ref().get_ref()
}
#[inline(always)]
#[must_use]
pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut I> {
let this = unsafe { self.get_unchecked_mut() };
this.inner.as_mut()
}
#[inline(always)]
#[must_use]
pub fn into_inner(self) -> Pin<Box<I>> {
self.inner
}
}
impl<I> AsyncInput for BoxAsyncInput<I>
where
I: AsyncInput + ?Sized,
{
type Item = I::Item;
#[inline(always)]
fn is_buffered(&self) -> bool {
self.get_ref().is_buffered()
}
#[inline(always)]
unsafe fn poll_read_unchecked(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
output: &mut [Self::Item],
index: usize,
count: usize,
) -> Poll<std::io::Result<usize>> {
unsafe { self.get_pin_mut().poll_read_unchecked(cx, output, index, count) }
}
}