diff options
Diffstat (limited to 'net/src')
-rw-r--r-- | net/src/transports/tcp.rs | 12 | ||||
-rw-r--r-- | net/src/transports/tls.rs | 12 | ||||
-rw-r--r-- | net/src/transports/udp.rs | 6 | ||||
-rw-r--r-- | net/src/transports/unix.rs | 12 |
4 files changed, 42 insertions, 0 deletions
diff --git a/net/src/transports/tcp.rs b/net/src/transports/tcp.rs index 37f00a7..37ad860 100644 --- a/net/src/transports/tcp.rs +++ b/net/src/transports/tcp.rs @@ -83,3 +83,15 @@ pub async fn listen_tcp(addr: &Addr, port: &Port) -> Result<TcpListener> { let listener = TcpListener::bind(address).await?; Ok(listener) } + +impl From<TcpStream> for Box<dyn Connection> { + fn from(conn: TcpStream) -> Self { + Box::new(TcpConn::new(conn)) + } +} + +impl From<TcpListener> for Box<dyn Listener> { + fn from(listener: TcpListener) -> Self { + Box::new(listener) + } +} diff --git a/net/src/transports/tls.rs b/net/src/transports/tls.rs index 01bb5aa..cbb3d99 100644 --- a/net/src/transports/tls.rs +++ b/net/src/transports/tls.rs @@ -138,3 +138,15 @@ pub async fn listen( .await .map(|l| Box::new(l) as Box<dyn Listener>) } + +impl From<TlsStream<TcpStream>> for Box<dyn Connection> { + fn from(conn: TlsStream<TcpStream>) -> Self { + Box::new(TlsConn::new(conn.get_ref().0.clone(), conn)) + } +} + +impl From<TlsListener> for Box<dyn Listener> { + fn from(listener: TlsListener) -> Self { + Box::new(listener) + } +} diff --git a/net/src/transports/udp.rs b/net/src/transports/udp.rs index 8a2fbec..9576876 100644 --- a/net/src/transports/udp.rs +++ b/net/src/transports/udp.rs @@ -73,3 +73,9 @@ pub async fn listen_udp(addr: &Addr, port: &Port) -> Result<UdpConn> { let udp_conn = UdpConn::new(conn); Ok(udp_conn) } + +impl From<UdpSocket> for Box<dyn Connection> { + fn from(conn: UdpSocket) -> Self { + Box::new(UdpConn::new(conn)) + } +} diff --git a/net/src/transports/unix.rs b/net/src/transports/unix.rs index e504934..0698975 100644 --- a/net/src/transports/unix.rs +++ b/net/src/transports/unix.rs @@ -74,3 +74,15 @@ pub fn listen_unix(path: &String) -> Result<UnixListener> { let listener = UnixListener::bind(path)?; Ok(listener) } + +impl From<UnixStream> for Box<dyn Connection> { + fn from(conn: UnixStream) -> Self { + Box::new(UnixConn::new(conn)) + } +} + +impl From<UnixListener> for Box<dyn Listener> { + fn from(listener: UnixListener) -> Self { + Box::new(listener) + } +} |