refactor: EVERYTHING
This commit is contained in:
parent
c746e594ca
commit
7ab0898413
17 changed files with 1410 additions and 728 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
||||
use tokio::net::{TcpStream, UnixStream};
|
||||
use tokio_listener::Connection;
|
||||
|
||||
use std::io::Result;
|
||||
use std::marker::Unpin;
|
||||
|
|
@ -9,6 +10,7 @@ use std::task::{Context, Poll};
|
|||
pub enum AbstractStream {
|
||||
Tcp(TcpStream),
|
||||
Uds(UnixStream),
|
||||
Listener(Connection),
|
||||
}
|
||||
|
||||
impl From<TcpStream> for AbstractStream {
|
||||
|
|
@ -23,6 +25,12 @@ impl From<UnixStream> for AbstractStream {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Connection> for AbstractStream {
|
||||
fn from(stream: Connection) -> Self {
|
||||
Self::Listener(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl Unpin for AbstractStream {}
|
||||
|
||||
impl AsyncRead for AbstractStream {
|
||||
|
|
@ -34,6 +42,7 @@ impl AsyncRead for AbstractStream {
|
|||
match &mut *self {
|
||||
Self::Tcp(stream) => pin!(stream).poll_read(cx, buf),
|
||||
Self::Uds(stream) => pin!(stream).poll_read(cx, buf),
|
||||
Self::Listener(stream) => pin!(stream).poll_read(cx, buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,6 +56,7 @@ impl AsyncWrite for AbstractStream {
|
|||
match &mut *self {
|
||||
Self::Tcp(stream) => pin!(stream).poll_write(cx, buf),
|
||||
Self::Uds(stream) => pin!(stream).poll_write(cx, buf),
|
||||
Self::Listener(stream) => pin!(stream).poll_write(cx, buf),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +64,7 @@ impl AsyncWrite for AbstractStream {
|
|||
match &mut *self {
|
||||
Self::Tcp(stream) => pin!(stream).poll_flush(cx),
|
||||
Self::Uds(stream) => pin!(stream).poll_flush(cx),
|
||||
Self::Listener(stream) => pin!(stream).poll_flush(cx),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +72,7 @@ impl AsyncWrite for AbstractStream {
|
|||
match &mut *self {
|
||||
Self::Tcp(stream) => pin!(stream).poll_shutdown(cx),
|
||||
Self::Uds(stream) => pin!(stream).poll_shutdown(cx),
|
||||
Self::Listener(stream) => pin!(stream).poll_shutdown(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue