use std::io::{
Read,
Result,
};
pub trait Input {
type Item;
unsafe fn read_unchecked(
&mut self,
output: &mut [Self::Item],
index: usize,
count: usize,
) -> Result<usize>;
}
impl<R> Input for R
where
R: Read + ?Sized,
{
type Item = u8;
#[inline(always)]
unsafe fn read_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize> {
debug_assert!(
index
.checked_add(count)
.is_some_and(|end| end <= output.len()),
"unchecked read range exceeds output buffer"
);
let target = unsafe {
core::slice::from_raw_parts_mut(
output.as_mut_ptr().add(index),
count,
)
};
self.read(target)
}
}