kumo_tls_helper/
traits.rs1use std::fmt::Debug;
4use tokio::io::{AsyncRead, AsyncWrite};
5use tokio::net::TcpStream;
6use tokio_openssl::SslStream;
7use tokio_rustls::client::TlsStream as TlsClientStream;
8use tokio_rustls::server::TlsStream as TlsServerStream;
9
10pub trait AsyncReadAndWrite: AsyncRead + AsyncWrite + Debug + Unpin + Send + Sync {
11 fn try_into_tcp_stream(self) -> Result<TcpStream, Self>
15 where
16 Self: Sized,
17 {
18 Err(self)
19 }
20}
21impl AsyncReadAndWrite for TlsClientStream<TcpStream> {}
22impl AsyncReadAndWrite for TlsClientStream<BoxedAsyncReadAndWrite> {}
23impl AsyncReadAndWrite for TlsServerStream<TcpStream> {}
24impl AsyncReadAndWrite for TlsServerStream<BoxedAsyncReadAndWrite> {}
25
26impl AsyncReadAndWrite for TcpStream {
27 fn try_into_tcp_stream(self) -> Result<TcpStream, Self> {
29 Ok(self)
30 }
31}
32impl AsyncReadAndWrite for SslStream<TcpStream> {}
33impl AsyncReadAndWrite for SslStream<BoxedAsyncReadAndWrite> {}
34impl AsyncReadAndWrite for tokio::net::UnixStream {}
35
36pub type BoxedAsyncReadAndWrite = Box<dyn AsyncReadAndWrite>;
37
38impl AsyncReadAndWrite for BoxedAsyncReadAndWrite {}