use std::io;
use tokio_uring::buf::{BoundedBuf, BoundedBufMut};
pub trait UringStream {
fn read<B: BoundedBuf + BoundedBufMut>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<usize>, B)>;
fn write_all<B: BoundedBuf>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<()>, B)>;
fn shutdown(&self, how: std::net::Shutdown) -> io::Result<()>;
}
impl UringStream for tokio_uring::net::UnixStream {
fn read<B: BoundedBuf + BoundedBufMut>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<usize>, B)> {
tokio_uring::net::UnixStream::read(self, buf)
}
fn write_all<B: BoundedBuf>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<()>, B)> {
tokio_uring::net::UnixStream::write_all(self, buf)
}
fn shutdown(&self, how: std::net::Shutdown) -> io::Result<()> {
tokio_uring::net::UnixStream::shutdown(self, how)
}
}
impl UringStream for tokio_uring::net::TcpStream {
fn read<B: BoundedBuf + BoundedBufMut>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<usize>, B)> {
tokio_uring::net::TcpStream::read(self, buf)
}
fn write_all<B: BoundedBuf>(
&self,
buf: B,
) -> impl std::future::Future<Output = (io::Result<()>, B)> {
tokio_uring::net::TcpStream::write_all(self, buf)
}
fn shutdown(&self, how: std::net::Shutdown) -> io::Result<()> {
tokio_uring::net::TcpStream::shutdown(self, how)
}
}