aboutsummaryrefslogtreecommitdiff
path: root/net/src/transports
diff options
context:
space:
mode:
Diffstat (limited to 'net/src/transports')
-rw-r--r--net/src/transports/tcp.rs22
-rw-r--r--net/src/transports/tls.rs22
-rw-r--r--net/src/transports/udp.rs14
-rw-r--r--net/src/transports/unix.rs25
4 files changed, 77 insertions, 6 deletions
diff --git a/net/src/transports/tcp.rs b/net/src/transports/tcp.rs
index 7cd7127..99243b5 100644
--- a/net/src/transports/tcp.rs
+++ b/net/src/transports/tcp.rs
@@ -7,9 +7,9 @@ use smol::{
};
use crate::{
- connection::Connection,
+ connection::{Connection, ToConn},
endpoint::{Addr, Endpoint, Port},
- listener::ConnListener,
+ listener::{ConnListener, ToListener},
Error, Result,
};
@@ -95,3 +95,21 @@ impl From<TcpListener> for Box<dyn ConnListener> {
Box::new(listener)
}
}
+
+impl ToConn for TcpStream {
+ fn to_conn(self) -> Box<dyn Connection> {
+ self.into()
+ }
+}
+
+impl ToConn for TcpConn {
+ fn to_conn(self) -> Box<dyn Connection> {
+ Box::new(self)
+ }
+}
+
+impl ToListener for TcpListener {
+ fn to_listener(self) -> Box<dyn ConnListener> {
+ self.into()
+ }
+}
diff --git a/net/src/transports/tls.rs b/net/src/transports/tls.rs
index bc928b0..8a43d7d 100644
--- a/net/src/transports/tls.rs
+++ b/net/src/transports/tls.rs
@@ -9,9 +9,9 @@ use smol::{
};
use crate::{
- connection::Connection,
+ connection::{Connection, ToConn},
endpoint::{Addr, Endpoint, Port},
- listener::ConnListener,
+ listener::{ConnListener, ToListener},
Error, Result,
};
@@ -150,3 +150,21 @@ impl From<TlsListener> for Box<dyn ConnListener> {
Box::new(listener)
}
}
+
+impl ToConn for TlsStream<TcpStream> {
+ fn to_conn(self) -> Box<dyn Connection> {
+ self.into()
+ }
+}
+
+impl ToConn for TlsConn {
+ fn to_conn(self) -> Box<dyn Connection> {
+ Box::new(self)
+ }
+}
+
+impl ToListener for TlsListener {
+ fn to_listener(self) -> Box<dyn ConnListener> {
+ self.into()
+ }
+}
diff --git a/net/src/transports/udp.rs b/net/src/transports/udp.rs
index 9576876..a8b505c 100644
--- a/net/src/transports/udp.rs
+++ b/net/src/transports/udp.rs
@@ -4,7 +4,7 @@ use async_trait::async_trait;
use smol::net::UdpSocket;
use crate::{
- connection::Connection,
+ connection::{Connection, ToConn},
endpoint::{Addr, Endpoint, Port},
Error, Result,
};
@@ -79,3 +79,15 @@ impl From<UdpSocket> for Box<dyn Connection> {
Box::new(UdpConn::new(conn))
}
}
+
+impl ToConn for UdpSocket {
+ fn to_conn(self) -> Box<dyn Connection> {
+ self.into()
+ }
+}
+
+impl ToConn for UdpConn {
+ fn to_conn(self) -> Box<dyn Connection> {
+ Box::new(self)
+ }
+}
diff --git a/net/src/transports/unix.rs b/net/src/transports/unix.rs
index c546333..3867040 100644
--- a/net/src/transports/unix.rs
+++ b/net/src/transports/unix.rs
@@ -6,7 +6,12 @@ use smol::{
net::unix::{UnixListener, UnixStream},
};
-use crate::{connection::Connection, endpoint::Endpoint, listener::ConnListener, Error, Result};
+use crate::{
+ connection::{Connection, ToConn},
+ endpoint::Endpoint,
+ listener::{ConnListener, ToListener},
+ Error, Result,
+};
/// Unix domain socket implementation of the [`Connection`] trait.
pub struct UnixConn {
@@ -86,3 +91,21 @@ impl From<UnixListener> for Box<dyn ConnListener> {
Box::new(listener)
}
}
+
+impl ToConn for UnixStream {
+ fn to_conn(self) -> Box<dyn Connection> {
+ self.into()
+ }
+}
+
+impl ToConn for UnixConn {
+ fn to_conn(self) -> Box<dyn Connection> {
+ Box::new(self)
+ }
+}
+
+impl ToListener for UnixListener {
+ fn to_listener(self) -> Box<dyn ConnListener> {
+ self.into()
+ }
+}