use futures_core::future::BoxFuture;
use std::borrow::Cow;
use std::io;
mod tokio;
mod unwrapper;
pub use self::tokio::TokioAsyncIoEnv;
pub use self::unwrapper::ArcUnwrappingAsyncIoEnv;
pub trait AsyncIoEnvironment {
type IoHandle;
fn read_all(&mut self, fd: Self::IoHandle) -> BoxFuture<'static, io::Result<Vec<u8>>>;
fn write_all<'a>(
&mut self,
fd: Self::IoHandle,
data: Cow<'a, [u8]>,
) -> BoxFuture<'a, io::Result<()>>;
fn write_all_best_effort(&mut self, fd: Self::IoHandle, data: Vec<u8>);
}
impl<'b, T> AsyncIoEnvironment for &'b mut T
where
T: 'b + ?Sized + Send + Sync + AsyncIoEnvironment,
T::IoHandle: Send,
{
type IoHandle = T::IoHandle;
fn read_all(&mut self, fd: Self::IoHandle) -> BoxFuture<'static, io::Result<Vec<u8>>> {
(**self).read_all(fd)
}
fn write_all<'a>(
&mut self,
fd: Self::IoHandle,
data: Cow<'a, [u8]>,
) -> BoxFuture<'a, io::Result<()>> {
(**self).write_all(fd, data)
}
fn write_all_best_effort(&mut self, fd: Self::IoHandle, data: Vec<u8>) {
(**self).write_all_best_effort(fd, data);
}
}