use std::io::{self, Read, Write};
use super::{AsyncBytesRead, AsyncBytesWrite};
#[derive(Debug, Default, Clone, Copy)]
pub struct BlockingIo<T>(pub T);
impl<T> BlockingIo<T> {
pub const fn new(inner: T) -> Self {
Self(inner)
}
pub fn get_mut(&mut self) -> &mut T {
&mut self.0
}
pub fn into_inner(self) -> T {
self.0
}
}
impl<T: Read> AsyncBytesRead for BlockingIo<T> {
type Error = io::Error;
async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), io::Error> {
self.0.read_exact(buf)
}
}
impl<T: Write> AsyncBytesWrite for BlockingIo<T> {
type Error = io::Error;
async fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {
self.0.write_all(buf)
}
async fn flush(&mut self) -> Result<(), io::Error> {
self.0.flush()
}
}