use crate::io::{Read, Write};
pub struct StdIoReader<R: std::io::Read> {
reader: R,
}
impl<R: std::io::Read> StdIoReader<R> {
#[inline(always)]
pub fn new(reader: R) -> Self {
Self { reader }
}
#[inline(always)]
pub fn extract(self) -> R {
self.reader
}
}
impl<R: std::io::Read> From<R> for StdIoReader<R> {
fn from(value: R) -> Self {
Self::new(value)
}
}
impl<R: std::io::Read> Read<std::io::Error> for StdIoReader<R> {
#[inline(always)]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), std::io::Error> {
self.reader.read_exact(buf)
}
}
pub struct StdIoWriter<W: std::io::Write> {
writer: W,
}
impl<W: std::io::Write> StdIoWriter<W> {
#[inline(always)]
pub fn new(writer: W) -> Self {
Self { writer }
}
#[inline(always)]
pub fn extract(self) -> W {
self.writer
}
}
impl<W: std::io::Write> From<W> for StdIoWriter<W> {
fn from(value: W) -> Self {
Self::new(value)
}
}
impl<W: std::io::Write> Write<std::io::Error> for StdIoWriter<W> {
#[inline(always)]
fn write_all(&mut self, buf: &[u8]) -> Result<(), std::io::Error> {
self.writer.write_all(buf)
}
#[inline]
fn flush(&mut self) -> Result<(), std::io::Error> {
self.writer.flush()
}
}