use std::io;
use crate::Input;
#[must_use]
#[repr(transparent)]
pub struct InputRef<'a, I>
where
I: Input + ?Sized,
{
inner: &'a mut I,
}
impl<'a, I> InputRef<'a, I>
where
I: Input + ?Sized,
{
#[inline(always)]
pub const fn new(inner: &'a mut I) -> Self {
Self { inner }
}
#[inline(always)]
#[must_use]
pub fn get_ref(&self) -> &I {
self.inner
}
#[inline(always)]
#[must_use]
pub fn get_mut(&mut self) -> &mut I {
self.inner
}
#[inline(always)]
#[must_use]
pub fn into_inner(self) -> &'a mut I {
self.inner
}
}
impl<I> Input for InputRef<'_, 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)
}
}