1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-27 06:09:02 +02:00

add actix stream trait (#276)

This commit is contained in:
fakeshadow
2021-02-20 09:25:22 -08:00
committed by GitHub
parent 2cfe1d88ad
commit 75d7ae3139
5 changed files with 297 additions and 53 deletions

View File

@ -77,6 +77,44 @@ pub mod net {
#[cfg(unix)]
pub use tokio::net::{UnixDatagram, UnixListener, UnixStream};
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite};
/// Trait for generic over tokio stream types and various wrapper types around them.
pub trait ActixStream: AsyncRead + AsyncWrite + Unpin + 'static {
/// poll stream and check read readiness of Self.
///
/// See [tokio::net::TcpStream::poll_read_ready] for detail
fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
/// poll stream and check write readiness of Self.
///
/// See [tokio::net::TcpStream::poll_write_ready] for detail
fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
}
impl ActixStream for TcpStream {
fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
TcpStream::poll_read_ready(self, cx)
}
fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
TcpStream::poll_write_ready(self, cx)
}
}
#[cfg(unix)]
impl ActixStream for UnixStream {
fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
UnixStream::poll_read_ready(self, cx)
}
fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
UnixStream::poll_write_ready(self, cx)
}
}
}
pub mod time {