use std::io;
use crate::Input;
#[must_use]
#[repr(transparent)]
pub struct BoxInput<I>
where
I: Input + ?Sized,
{
inner: Box<I>,
}
impl<I> BoxInput<I>
where
I: Input + ?Sized,
{
#[inline(always)]
pub const fn new(inner: Box<I>) -> Self {
Self { inner }
}
#[inline(always)]
#[must_use]
pub fn get_ref(&self) -> &I {
self.inner.as_ref()
}
#[inline(always)]
#[must_use]
pub fn get_mut(&mut self) -> &mut I {
self.inner.as_mut()
}
#[inline(always)]
#[must_use]
pub fn into_inner(self) -> Box<I> {
self.inner
}
}
impl<I> Input for BoxInput<I>
where
I: Input + ?Sized,
{
type Item = I::Item;
#[inline(always)]
fn is_buffered(&self) -> bool {
self.inner.is_buffered()
}
#[inline(always)]
unsafe fn read_unchecked(&mut self, output: &mut [Self::Item], index: usize, count: usize) -> io::Result<usize> {
unsafe { self.inner.read_unchecked(output, index, count) }
}
#[inline(always)]
fn read(&mut self, output: &mut [Self::Item]) -> io::Result<usize> {
self.inner.read(output)
}
#[inline(always)]
unsafe fn read_fully_unchecked(
&mut self,
output: &mut [Self::Item],
index: usize,
count: usize,
) -> io::Result<usize> {
unsafe { self.inner.read_fully_unchecked(output, index, count) }
}
#[inline(always)]
fn read_fully(&mut self, output: &mut [Self::Item]) -> io::Result<usize> {
self.inner.read_fully(output)
}
}