use std::io;
use crate::Output;
#[must_use]
#[repr(transparent)]
pub struct OutputRef<'a, O>
where
O: Output + ?Sized,
{
inner: &'a mut O,
}
impl<'a, O> OutputRef<'a, O>
where
O: Output + ?Sized,
{
#[inline(always)]
pub const fn new(inner: &'a mut O) -> Self {
Self { inner }
}
#[inline(always)]
#[must_use]
pub fn get_ref(&self) -> &O {
self.inner
}
#[inline(always)]
#[must_use]
pub fn get_mut(&mut self) -> &mut O {
self.inner
}
#[inline(always)]
#[must_use]
pub fn into_inner(self) -> &'a mut O {
self.inner
}
}
impl<O> Output for OutputRef<'_, O>
where
O: Output + ?Sized,
{
type Item = O::Item;
#[inline(always)]
fn is_buffered(&self) -> bool {
self.inner.is_buffered()
}
#[inline(always)]
unsafe fn write_unchecked(&mut self, input: &[Self::Item], index: usize, count: usize) -> io::Result<usize> {
unsafe { self.inner.write_unchecked(input, index, count) }
}
#[inline(always)]
fn write(&mut self, input: &[Self::Item]) -> io::Result<usize> {
self.inner.write(input)
}
#[inline(always)]
unsafe fn write_fully_unchecked(&mut self, input: &[Self::Item], index: usize, count: usize) -> io::Result<()> {
unsafe { self.inner.write_fully_unchecked(input, index, count) }
}
#[inline(always)]
fn write_fully(&mut self, input: &[Self::Item]) -> io::Result<()> {
self.inner.write_fully(input)
}
#[inline(always)]
fn flush(&mut self) -> io::Result<()> {
self.inner.flush()
}
}